Computing.Net > Forums > Unix > Shell variables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shell variables

Reply to Message Icon

Name: pbekal
Date: December 8, 2005 at 06:56:43 Pacific
OS: Unix
CPU/Ram: Risc
Comment:

When I put the output of a command into a variable the leading spaces are lost. Below shows the shell b.sh with the variable "a" where the leading spaces are lost. In the second instance doing the same command on the command prompt show the leading spaces.
How can I have the leading spaces saved in the variable in the shell.
> more b.sh
a=`bdf|grep /orpsoft/data001/oradata/PSTISPRD`
echo $a

>b.sh
40960000 38977784 1966776 95% /orpsoft/data001/oradata/PSTISPRD

> bdf|grep /orpsoft/data001/oradata/PSTISPRD
40960000 38977784 1966776 95% /orpsoft/data001/oradata/PSTISPRD



Sponsored Link
Ads by Google

Response Number 1
Name: pbekal
Date: December 8, 2005 at 06:58:52 Pacific
Reply:

The leading spaces was lost when I posted the message in this forum


0

Response Number 2
Name: nails
Date: December 8, 2005 at 08:44:51 Pacific
Reply:

The normal method for saving whitespace is to use double quotes. What happens when you execute:

echo "$a"


0

Response Number 3
Name: WilliamRobertson
Date: December 8, 2005 at 10:41:33 Pacific
Reply:

Note that the shell expands variables before executing the "echo" command, so if $a has the value " x", then

echo $a

becomes (if my post comes out right)

echo  x

which is the same as

echo x

I agree with Nails, you need to quote it.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Copying files print user info script



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Shell variables

Shell variable in AWK www.computing.net/answers/unix/shell-variable-in-awk/6651.html

passing awk variables to shell www.computing.net/answers/unix/passing-awk-variables-to-shell/5865.html

Passing Bourne shell variables www.computing.net/answers/unix/passing-bourne-shell-variables/1958.html