LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-24-2007, 09:33 PM   #1
gmccammon
LQ Newbie
 
Registered: Jun 2007
Posts: 1

Rep: Reputation: 0
Question Trying to get a script to accept a command line argument


I'm attempting to write a script for a class assignment that takes a command line argument and prints certain elements from the /etc/passwd file.

I created a script titled "printpasswd". In this script I included the following command:

$ awk -F":" '{ print $1 ", " $3 ", " $4 ", " $6 ", " $7}' /etc/passwd

then when you type sh printpaswd it runs OK and does what it is supposed to.

Only after I read the assignment again, did I see that the script needs to have the file name passed as an argument and not specified in the script.

I'm trying to figure out how to get the script to expect the file name so it runs properly when I type sh printpasswd /etc/passwd

I trired this, but it didn't work either:
$ awk -F":" '{ print $1 ", " $3 ", " $4 ", " $6 ", " $7}' $1

Any assistance would be greatly appreciated.

Greg
 
Old 06-24-2007, 10:51 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
Discuss with your classmates or tutor how quotation marks work on the bash command line. Single quotes cause bash to do no interpretation of $ or anything else between them; double quotation marks work otherwise.

If you want, experiment with echo instead of awk to get a more immediate feel of what happens to your command line arguments. Discuss this with your tutor and your classmates also.

Have fun!

Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script 'for each command line argument' true_atlantis Linux - Newbie 3 01-28-2009 02:51 PM
client server raw socket without using command line argument edens_2001 Linux - Networking 1 03-13-2007 08:14 AM
Finding the last command line argument (bash) pete1234 Programming 20 10-30-2006 11:20 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 05:35 PM
script for a command that won't accept wildcard value hemp4fuel Programming 4 05-24-2004 06:30 AM


All times are GMT -5. The time now is 06:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration