Register
It is currently Sat Oct 25, 2014 8:56 pm

passing output from a command into a variable


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sat Jan 23, 2010 10:15 pm   

Joined: Sat Jan 23, 2010 9:51 pm
Posts: 1
I thought I would learn shell scripting by trying something simple, but it hasn't turned out that way.
My plan is to use the wc command within my script to print some stats.
if my script is script1, and I have a file myprog.c, then ./myscript myprog.c would print:
File: myprog.c
Lines: 16

Code:
#!/bin/sh
printf "File: %s\n" $1
var=`wc -l $1`
printf "Lines: %s\n" $var


I get this as output:
File: myprog.c
./myscript: 4: 16: not found

im guessing that I can't use the $1 within the backwards quotes, but I need that wc command to run on whatever file I pass as an argument. Any help would be appreciated.


Top
 Profile  
 PostPosted: Sat Jan 23, 2010 11:39 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 550
Change the shebang for #!/bin/bash -x, and please give the complete output of the script.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP