Results 1 to 9 of 9
i'm supposed to code a linux shell script named fileinof which allows users to view info on files in a specified directory and the script will accept one optional parameter ...
- 11-29-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
bash scripting newbie can someone tell me what i'm doing wrong?
i'm supposed to code a linux shell script named fileinof which allows users to view info on files in a specified directory and the script will accept one optional parameter as a directory path.
here's what i got so far
$ cat fileinfo
#!/bin/s
if [ $# -ne 1 ]; then
echo 1>&2 Usage: fileinfo [directory path]
exit 127
fi
but at the command line when i enter $ ./fileinfo it says bash: $: command not found. WHY? am i missing something? i can't figure it out.
- 11-29-2007 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
Could be the 1st line:
#!/bin/s
Should be:
#!/bin/bash
- 11-29-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
I fixed that problem, but it still gives me the same error:
bash: $: command not found
- 11-29-2007 #4
You are typing $ then the command. You need not type the $.
- 11-29-2007 #5Linux User
- Join Date
- Jun 2007
- Posts
- 318
How are you trying to run the script. It should be:
./fileinfo
Also you need quotes around the error message:
echo 1>&2 'Usage: fileinfo [directory path]'
- 11-29-2007 #6Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Make the file executable with the chmod command.
Regards
- 11-29-2007 #7Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
thank you! i feel like such an idiot.
how would i process the files in the directory that was entered?
- 11-29-2007 #8Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
or i mean how would i check if that directory existed?
- 11-29-2007 #9Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
You can do that with the test command.
I highly recommend you to read something about shell scripting. Go here for the tutorials:
Linux Shell Scripting Tutorial - A Beginner's handbook
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://tldp.org/LDP/abs/html/
Regards


Reply With Quote
