LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-25-2010, 05:20 AM   #1
wahming
Member
 
Registered: Jan 2007
Posts: 133

Rep: Reputation: 15
Bash Script argument disappears


I call my script with ./script -e arg2
However, $@ only shows me arg2. Surprisingly, if I use ./script -s arg2, $@ shows me both arguments. What's going on?
 
Old 10-25-2010, 05:31 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
I don't see an invocation option of -e in the bash manpage, and -s doesn't seem as though it would do as you describe..

So, figuring that this has something to do with the code in the script, it would perhaps help to see the code. What do the -e and -s options do within the code? Anything?

Also, you're only passing one arg in your examples, so how can either example show you both args?

Last edited by GrapefruiTgirl; 10-25-2010 at 05:33 AM.
 
Old 10-25-2010, 06:28 AM   #3
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
-e is an option to echo but -s is not.
Code:
echo -e arg2
arg2

echo -s arg2
-s arg2
This is one way to get -e to echo, but it creates a leading space in the output.
Code:
echo '' -e arg2
 -e arg2
When echoing to the screen the leading space can be removed using $' \b', which in bash is a space followed by a backspace.
Code:
echo $' \b'-e arg2
-e arg2
 
Old 10-25-2010, 09:34 PM   #4
wahming
Member
 
Registered: Jan 2007
Posts: 133

Original Poster
Rep: Reputation: 15
Grapefruit - sorry, I was a little sleepy when I posted, so maybe my question wasn't as clear as it might have been. -e would be arg1, and arg2 would be, well, arg2. `echo $@` in my script would only display arg2, but not arg1 in some cases.

Kenhelm - thanks! You hit the nail on the head, and printf "%s " works beautifully.
 
Old 10-26-2010, 05:03 AM   #5
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
No problem! Kenhelm did indeed hit it right on.

If that solves the issue fully, you can mark this thread solved if you like, using Thread Tools menu, above the first post.

Have a good day!
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [bash] option followed by argument list hashbang#! Programming 5 02-08-2010 02:18 PM
bash script 'for each command line argument' true_atlantis Linux - Newbie 3 01-28-2009 01:51 PM
Bash script: how do I select second-to-last argument in a list Robert S Linux - Software 2 11-23-2007 03:06 PM
BASH: rename an argument of the script sylvaticus Programming 2 05-21-2007 08:20 AM
how to find out if argument is number: bash kubicon Linux - Newbie 1 09-19-2003 04:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:41 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
Open Source Consulting | Domain Registration