Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (3) </ 1 [2] 3 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: How to assing a line break to a variable in bash?< Next Oldest | Next Newest >
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: Oct. 22 2006,23:47 QUOTE

Solved. There was missing one double quote AND I didn't knew if I need to check variable if it contains a path it has to be done like this:
Code Sample
if [ -z "$PROGRAMPATH" ]
then
 echo "Program not found."
 exit 1
fi


Double quotes around variable name. ;)
Then it looks that variable as text.

Need to read more bash manuals. ;)


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Oct. 23 2006,03:58 QUOTE

Quotes on variables can be a frustrating thing...I still don't fully understand all the differences between using them in some cases and not in others.  Sometimes it works as desired with or without quotes, sometimes it works either way but with different results depending on whether or not quotes are used.  Other times you definitely need quotes.

--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Oct. 23 2006,15:02 QUOTE

I try to use quotes when you mean to parse the variables as strings.

btw, please please double check your topic titles - they can be misleading... :p
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Oct. 23 2006,15:41 QUOTE

One thing I've only recently noticed, and still attempting to get a solid understanding of it, is how commandline parameters are affected by quotes.

If you have this script:
Code Sample
for i in $@; do echo $i;done
and you run scriptname 1 2 3 or scriptname "1 2 3", they both print 3 parameters.
If the $@ in the script is enclosed in quotes ("$@"), you notice a difference. Sending "1 2 3" in quotes as a single string is interpreted as $1 (a single parameter), but sending 1 2 3 without quotes is interpreted as 3 separate parameters.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Oct. 23 2006,16:06 QUOTE

Interesting, I was doing something with that quite recently as well.
man bash:
Code Sample
  Special Parameters
      The  shell  treats  several parameters specially.  These parameters may
      only be referenced; assignment to them is not allowed.
      *      Expands to the positional parameters, starting from  one.   When
             the  expansion occurs within double quotes, it expands to a sin-
             gle word with the value of each parameter separated by the first
             character of the IFS special variable.  That is, "$*" is equiva-
             lent to "$1c$2c...", where c is the first character of the value
             of  the IFS variable.  If IFS is unset, the parameters are sepa-
             rated by spaces.  If IFS is  null,  the  parameters  are  joined
             without intervening separators.
      @      Expands  to  the positional parameters, starting from one.  When
             the  expansion  occurs  within  double  quotes,  each  parameter
             expands to a separate word.  That is, "$@" is equivalent to "$1"
             "$2" ...  When there are no positional parameters, "$@"  and  $@
             expand to nothing (i.e., they are removed).
They're 'special'...
Back to top
Profile PM 
10 replies since Oct. 22 2006,16:14 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (3) </ 1 [2] 3 >/
reply to topic new topic new poll
Quick Reply: How to assing a line break to a variable in bash?

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code