Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display \\ and \ ?

Status
Not open for further replies.

lotamoka

MIS
Jul 15, 2007
43
US
I have following script ..
#!/bin/ksh
echo "Put filesystem name"
read filesystem
echo $filesystem

when i input \\brwsmxsusr01\d$ it ignores \\ and \ and output looks like
rwsmxsusr01d$
Is there way to fix these ?
 
\ is a meta character. It basically means ignore the special meaning of the next character and just use it as it. So when you enter

\\brwsmxsusr01

the shell will display the next character instead of acting on it. So what you see is

\brwsmxsusr01

If you want two back slashes, you would need to enter it like this:

\\\\brwsmxsusr01

The second and forth back slashes would then be printed (instead of acted on) and you would see

\\brwsmxsusr01

Add a little color to your PUTTY terminal: faq52-6627
 
Hi
sbrews
Output litle improved ..
$ ./test.sh
Put filesystem name
\\\\brwsmxsusr01\\d$
\brwsmxsusr01\d$
$
I want out put look like \\brwsmxsusr01\d$ ..any more suggestion ?
 
Hmm, work for me:
Code:
geir@edgy:~/ShellScripting$ cat kshelltest.ksh
#!/usr/bin/ksh
echo "Put filesystem name"
read filesystem
echo $filesystem
geir@edgy:~/ShellScripting$ ./kshelltest.ksh
Put filesystem name
\\\\brwsmxsusr01\\d$
\\brwsmxsusr01\d$
And just to make shure:
Code:
geir@edgy:~/ShellScripting$ which ksh
/usr/bin/ksh
geir@edgy:~/ShellScripting$ ls -l /usr/bin/ksh
lrwxrwxrwx 1 root root 29 2006-10-29 17:40 /usr/bin/ksh -> /etc/alternatives/usr.bin.ksh
geir@edgy:~/ShellScripting$ ls -l /etc/alternatives/usr.bin.ksh
lrwxrwxrwx 1 root root 10 2006-10-29 17:40 /etc/alternatives/usr.bin.ksh -> /bin/ksh93
geir@edgy:~/ShellScripting$ ls -l /bin/ksh93
-rwxr-xr-x 1 root root 1028188 2006-06-20 05:09 /bin/ksh93
geir@edgy:~/ShellScripting$
Using ksh93...
:)
 
Below is information u requested ..
$ which ksh
/usr/bin/ksh
$ ls -l /usr/bin/ksh
-r-xr-xr-x 4 bin bin 230072 Apr 13 06:08 /usr/bin/ksh
$ uname -a
AIX brwstsm2 2 5 000E4ADC4C00
$ oslevel
5.2.0.0
$
 
Hmm.... I am seeing two different results - for the ksh93 systems, it works as I described, for the older versions of ksh, it truncates it to on backslash.

on a side note:

Since you appear to be running this on an AIX system - is there any reason you are using windows pathing (backslashes) instead of slashes?

Add a little color to your PUTTY terminal: faq52-6627
 
Looks like there is a bug/issue with older versions of KSH and displaying backslashes.

This: \\\\test\\dir
should produce this: \\test\dir

and indeed it does on the newer version of ksh.
The older version of ksh (88, I think) truncates the above to a single backslash: \test\dir

See this link, section 1.9.2 for some more info on the backslash:
Add a little color to your PUTTY terminal: faq52-6627
 
Hi
This is a part in my other script where it gets windows filesystem name and queries TSM to find whether that file system is backed up. So looks like i don't have any other option.
 
Ok, after doing some more research, it looks like this will do the trick:

Code:
#!/bin/ksh
echo "Put filesystem name"
[b]read -r filesystem
print -r $filesystem[/b]

note the changes in the read and the change from the echo to the print -r.

The quick and limited testing I did on my AIX system gave the desired results.

Add a little color to your PUTTY terminal: faq52-6627
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top