f



How to change "/" to "\"

Now, the output as below

/a/b/c.txt
b/c.txt
x:/b/c.txt  , Need to change x:\b\c.txt


#!/bin/ksh
# echo.ksh
a=/a/b/c.txt
echo $a
echo ${a#/*/}
y=`echo x:/${a#/*/} | tr -s '/' '\'`
echo $y


0
moon
10/5/2005 3:24:43 AM
comp.unix.shell 15484 articles. 2 followers. Post Follow

3 Replies
737 Views

Similar Articles

[PageSpeed] 48

moon wrote:
> Now, the output as below
> 
> /a/b/c.txt
> b/c.txt
> x:/b/c.txt  , Need to change x:\b\c.txt
> 
> 
> #!/bin/ksh
> # echo.ksh
> a=/a/b/c.txt
> echo $a
> echo ${a#/*/}
> y=`echo x:/${a#/*/} | tr -s '/' '\'`
> echo $y
> 
> 

One escape necessary:
echo x:/${a#/*/} | tr -s '/' '\\'
Two escapes necessary:
y=`echo x:/${a#/*/} | tr -s '/' '\\\\'`; echo $y

-- 
Michael Tosch @ hp : com
0
Michael
10/5/2005 8:28:41 AM
My Machine : sun4u sparc SUNW,Ultra-4 , SunOS 5.6
#!/bin/ksh
# echo.ksh
a=/a/b/c.txt
echo $a
echo ${a#/*/}
y=`echo x:/${a#/*/} | tr -s '/' '\\\\'`;
echo $y
echo "\n"

Output as
/a/b/c.txt
b/c.txt
x:


"Michael Tosch" <eedmit@NO.eed.SPAM.ericsson.PLS.se> wrote in message
news:di02ro$aii$1@aken.eed.ericsson.se...
> moon wrote:
> > Now, the output as below
> >
> > /a/b/c.txt
> > b/c.txt
> > x:/b/c.txt  , Need to change x:\b\c.txt
> >
> >
> > #!/bin/ksh
> > # echo.ksh
> > a=/a/b/c.txt
> > echo $a
> > echo ${a#/*/}
> > y=`echo x:/${a#/*/} | tr -s '/' '\'`
> > echo $y
> >
> >
>
> One escape necessary:
> echo x:/${a#/*/} | tr -s '/' '\\'
> Two escapes necessary:
> y=`echo x:/${a#/*/} | tr -s '/' '\\\\'`; echo $y
>
> --
> Michael Tosch @ hp : com


0
moon
10/6/2005 7:53:08 AM
moon wrote:
> My Machine : sun4u sparc SUNW,Ultra-4 , SunOS 5.6
> #!/bin/ksh
> # echo.ksh
> a=/a/b/c.txt
> echo $a
> echo ${a#/*/}
> y=`echo x:/${a#/*/} | tr -s '/' '\\\\'`;
> echo $y
> echo "\n"
> 
> Output as
> /a/b/c.txt
> b/c.txt
> x:
> 

Aah, now I see.

/usr/ucb/"$y"
works but
echo "$y"
and
/bin/echo "$y"
produce your result.

See
man echo
and the special meaning of \a etc.

printf is an elegant solution:

printf "%s\n" "$y"

-- 
Michael Tosch @ hp : com
0
Michael
10/6/2005 8:43:15 PM
Reply: