- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- '\' sripped in when reading a 'line'
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2006 03:14 PM
тАО09-04-2006 03:14 PM
'\' sripped in when reading a 'line'
The shell in question is HP-UX implementation of /usr/bin/ksh or 1989 Korn implementation.
The idea is very simple: dump crontab to a file and discard anything that I do not need.
For example:
while read LINE; do
case "$LINE" in
*find*) continue ;;
*) echo "$LINE" >> newfile ;;
esac
done < file
I replaced echo with 'print' and tried to use -r for 'raw', no help. Each time '\' was stripped. For example:
find . -type f -exec ls -l {} \;
became
find . -type f -exec ls -l {} ;
I finally ended up using 'sed' to do what I wanted, however, I would like to do everything in shell.
So, my question is, how can I preserve '\' slash when reading a variable through either 'echo' or 'print' internal shell calls?
P.S. printf did not help either.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2006 03:36 PM
тАО09-04-2006 03:36 PM
Re: '\' sripped in when reading a 'line'
XX="AAA\tBBB"
print -r "${XX}"
- Tags:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2006 03:54 PM
тАО09-04-2006 03:54 PM
Re: '\' sripped in when reading a 'line'
XX="AAA\tBBB"
print -r "${XX}" > /var/tmp/myfile
od -c /var/tmp/myfile # to convince yourself it's there
read -r YY < /var/tmp/mfile
print -r "${YY}" # backslash should be intact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2006 04:06 PM
тАО09-04-2006 04:06 PM
Re: '\' sripped in when reading a 'line'
'man ksh' gives on interesting description:
"echo arg ...
When the first arg does not begin with a -, and none of the arguments contain a \, then echo prints each of its arguments separated by a space and terminated by a new-line.
Otherwise, the behavior of echo is system dependent and print or printf described below should be used."
'man echo' suggest the -n as replied before:
"Notes
Berkeley echo differs from this implementation. The former does not implement the backslash escapes. However, the semantics of the \c escape can be obtained by using the -n option. The echo command implemented as a built-in function of csh follows the Berkeley semantics (see csh(1))."
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-05-2006 08:50 PM
тАО09-05-2006 08:50 PM
Re: '\' sripped in when reading a 'line'
on my HP-UX 11i this runs fine:
while read -r LINE; do
case "$LINE" in
*find*) continue ;;
*) echo "$LINE" >> newfile ;;
esac
done < file
from man read:
Options and Arguments
read recognizes the following options and command-line arguments:
-r Do not treat a backslash character in any special
way. Consider each backslash to be part of the
input line.
HTH,
Art