Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-24-2007, 08:33 PM   #1
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.

Old 06-24-2007, 09:51 PM   #2
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.


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 01:51 PM
client server raw socket without using command line argument edens_2001 Linux - Networking 1 03-13-2007 07:14 AM
Finding the last command line argument (bash) pete1234 Programming 20 10-30-2006 10:20 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 04:35 PM
script for a command that won't accept wildcard value hemp4fuel Programming 4 05-24-2004 05:30 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:15 AM.

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