Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > bash scripting newbie can someone tell me what i'm doing wrong?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 11-29-2007   #1 (permalink)
Just 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.
jaay is offline  

Reply With Quote
Old 11-29-2007   #2 (permalink)
Linux User
 
Join Date: Jun 2007
Posts: 318
Could be the 1st line:

#!/bin/s

Should be:

#!/bin/bash
vsemaska is offline   Reply With Quote
Old 11-29-2007   #3 (permalink)
Just Joined!
 
Join Date: Nov 2007
Posts: 5
I fixed that problem, but it still gives me the same error:

bash: $: command not found
jaay is offline   Reply With Quote
Old 11-29-2007   #4 (permalink)
Linux Enthusiast
 
likwid's Avatar
 
Join Date: Dec 2006
Location: MA
Posts: 649
You are typing $ then the command. You need not type the $.
likwid is offline   Reply With Quote
Old 11-29-2007   #5 (permalink)
Linux 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]'
vsemaska is offline   Reply With Quote
Old 11-29-2007   #6 (permalink)
Linux Enthusiast
 
Franklin52's Avatar
 
Join Date: Aug 2006
Posts: 598
Make the file executable with the chmod command.

Regards
Franklin52 is offline   Reply With Quote
Old 11-29-2007   #7 (permalink)
Just 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?
jaay is offline   Reply With Quote
Old 11-29-2007   #8 (permalink)
Just Joined!
 
Join Date: Nov 2007
Posts: 5
or i mean how would i check if that directory existed?
jaay is offline   Reply With Quote
Old 11-29-2007   #9 (permalink)
Linux Enthusiast
 
Franklin52's Avatar
 
Join Date: Aug 2006
Posts: 598
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
Franklin52 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting, use regex as a case pattern paolodina Linux Programming & Scripting 2 05-10-2009 03:21 PM
Bash shell scripting doubts livingsword Linux Programming & Scripting 5 04-28-2007 08:55 PM
bash scripting arguments beyond $9 jrfk2 SuSE Linux Help 1 04-11-2007 07:39 PM
bash scripting..how to make it go line by line. ikiini Redhat / Fedora Linux Help 5 03-06-2007 06:46 AM
Bash scripting disruptive Redhat / Fedora Linux Help 1 06-29-2006 10:32 PM

Free Magazines
Free Network Mapping Tool for Microsoft® Office Visio® Professional 2007 Users
Don't map your network by hand – let LANsurveyor Express for Microsoft Visio Professional 2007 automatically create network diagrams for you.
subscribe
Free eBook:"Vulnerability Management for Dummies"
Get all the Facts and See How to Implement a Successful Vulnerability Management Program.
subscribe
Google vs The World: The Battle of the Message Security Vendors
With such a powerful name behind it, Google Message Security stands out in a sea of products that do exactly the same thing - or so they say.
subscribe

Safe, Secure Backup


All times are GMT. The time now is 02:58 AM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2