Unix Shell - Passing parmaters to a shell script

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > May 2004 > Passing parmaters to a shell script





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Passing parmaters to a shell script
Stu

2004-05-31, 6:06 pm

I have the following shell script:

cat t.sh
==========
spec="SPEC='C:\tmp\00000291.s00'"
sh t1.sh "${spec}"

that calls t1.sh

cat t1.sh
set -x
echo "|$1|"

When I run t.sh I see the following displayed to my screen
t1.sh
+ echo |SPEC='C:\tmp\00000291.s00'|
|SPEC='C: mp0291.s00'|

Can anybody tell why this is appearing ( |SPEC='C: mp0291.s00'| ) and
how to get rid of it. I just want this ( SPEC='C:\tmp\00000291.s00' ) to be
in $1 in t1.sh

Thanks for all that answer
Stephane CHAZELAS

2004-05-31, 6:06 pm

2004-05-28, 07:06(-07), Stu:
> I have the following shell script:
>
> cat t.sh
> ==========
> spec="SPEC='C:\tmp\00000291.s00'"
> sh t1.sh "${spec}"
>
> that calls t1.sh
>
> cat t1.sh
> set -x
> echo "|$1|"


echo can't be use to display arbitrary data as it expands escape
sequences (here \t for tab). Moreover, it's one of the least
portable commands, some of them even accept options (you can't
display "-n" then for instance). It's a command to avoid in
scripts except to display constant strings (litterals).

Use printf instead:

printf '%s\n' "|$1|"

--
Stephane
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com