9 Replies - 5631 Views - Last Post: 13 March 2011 - 01:51 AM Rate Topic: -----

#1 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Bash Scripting Problems, Maybe deprecated code?

Posted 08 March 2011 - 08:46 PM

Been working out of some Bash Scripting videos. Don't know why this code doesn't seem to run, even though I followed the instructions to the tee. The videos are a little dated though. But the only stuff not working are the \t \n and ^G.

#!/bin/sh

#Put file name we're saving the info above to in a var called fname
fname=./names.dat

# If the file does not exist create it
[ ! -f $fname ] && $fname

# Display the menu
clear
echo "\n\t\tThe Shell Programming Database"
echo "\t\t\tMain Menu"
echo "\nWhat do you want to do?\n"
echo "\t1. Create records"
echo "\t2. View records"
echo "\t3. Search for records"
echo "\t4. Delete records that match a pattern"
echo

# Ask for an answer
echo -n "Answer?"
read ans junk

# Decide what to do
case "$ans" in
        # read in the contact details from the keyboard
      1)
        echo "Please enter the following details:"
        echo
        #Ask user for name and address
        echo -n "Please enter your first name: "
        read first
        echo -n "Please enter your surname: "
        read sur
        echo -n "Enter your street address: "
        read street
        echo -n "Enter your city: "
        read city
        echo -n "Enter you state: "
        read state
        echo -n "Finally your zip code: "
        read zip

        # Append info entered to names.dat
        echo $first:$sur:$street:$city:$state:$zip >> $fname
        ;;
      2)
        # Show what's in the file
        echo
        echo Here are the current contacts recorded:
        echo
        (cat $fname | more)

        # count and tell user the number of these records stored
        echo
        echo There are `cat $fname | wc -l` contacts in the database.
        ;;
      3)
        echo Seach not finished
        ;;
      4)
        echo Search not finshed
        ;;
      *)
        echo "Really?^G"
        ;;
esac



Is This A Good Question/Topic? 0
  • +

Replies To: Bash Scripting Problems, Maybe deprecated code?

#2 westforduk  Icon User is offline

  • D.I.C Head

Reputation: 24
  • View blog
  • Posts: 140
  • Joined: 16-August 07

Re: Bash Scripting Problems, Maybe deprecated code?

Posted 11 March 2011 - 05:28 PM

Try using the -e flag.

echo -e "Words Words \t Words"


to allow special characters
Was This Post Helpful? 2
  • +
  • -

#3 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Bash Scripting Problems, Maybe deprecated code?

Posted 11 March 2011 - 10:40 PM

That worked! Thank You!
Was This Post Helpful? 0
  • +
  • -

#4 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Bash Scripting Problems, Maybe deprecated code?

Posted 12 March 2011 - 06:19 PM

I may have spoke too soon. It worked on \t and \n but not the ^G. I researched the man page for echo and saw I probably should have used \a instead.

Quote

\a alert (BEL)


While this does run instead of showing up in the text, there's no alert bell?
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5226
  • View blog
  • Posts: 27,000
  • Joined: 10-May 07

Re: Bash Scripting Problems, Maybe deprecated code?

Posted 12 March 2011 - 10:04 PM

Does your system have a bell?
Was This Post Helpful? 0
  • +
  • -

#6 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Bash Scripting Problems, Maybe deprecated code?

Posted 12 March 2011 - 10:55 PM

Looks like it to me...

# modprobe -l | grep pcspkr
/lib/modules/2.6.35.8/kernel/drivers/input/misc/pcspkr.ko

This post has been edited by Israel: 12 March 2011 - 11:34 PM

Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5226
  • View blog
  • Posts: 27,000
  • Joined: 10-May 07

Re: Bash Scripting Problems, Maybe deprecated code?

Posted 12 March 2011 - 11:02 PM

Can you cause an audio beep with any other program? Either a wrong key press in Bios, or interrupt the bootup sequence & fill the keyboard buffer.
Was This Post Helpful? 0
  • +
  • -

#8 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Bash Scripting Problems, Maybe deprecated code?

Posted 12 March 2011 - 11:44 PM

Yeah, this is a new distro for me so I checked. I did get a little beep when hit some input during the boot sequence.
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5226
  • View blog
  • Posts: 27,000
  • Joined: 10-May 07

Re: Bash Scripting Problems, Maybe deprecated code?

Posted 13 March 2011 - 12:30 AM

I know that there is a device for the sound card, /dev/audio is usually a symbolic link to the sound card block device. I think that there is (or used to be) one for the system speaker as well. Maybe there is a kernel modules, something like pcspkr?

Depending on the distro, they may have done away with such legacy hardware devices.
Was This Post Helpful? 1
  • +
  • -

#10 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Bash Scripting Problems, Maybe deprecated code?

Posted 13 March 2011 - 01:51 AM

I did post the path to my module for pcspkr, but I didn't know it was linked in /dev. Apparently it doesn't exist there in this distro. Whatever the case I think I'll let it die for now. This isn't for work or school, I just wanted to make sure I was learning it right. Thanks for your help.

This post has been edited by Israel: 13 March 2011 - 01:55 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1