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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bash script glitch

Status
Not open for further replies.

santanudas

Technical User
Mar 18, 2002
121
GB
I’ve got another problem with bash script. If I do this on the console I get it write:
Code:
[MacUsers@pcge ~]$ find ~/scripts -type l | grep iTest
/home/MacUsers/scripts/iTest File
[MacUsers@pcge ~]$ find ~/scripts -type l | grep iTest | sed 's/ /\\ /g'
/home/MacUsers/scripts/iTest\ File
But running it as a script, I get it wrong:
Code:
#!/bin/bash -f
#
OLDIFS=$IFS
IFS=''
for file in $( find ~/scripts -type l | grep iTest )
do
  echo $file
done
DAS=`echo ${file} | tr '' \\\n | sed 's/ /\\ /g'`
echo "The new one :: " $DAS
Any idea why? Any help is very much appreciated. Many Thanks!!

 
Hi guys,

I have fixed that (I hope so.)I forgot to mention that I was trying that code on OS X. Replacing
Code:
sed 's/ /\\ /g'
with
Code:
sed 's/ /\\\ /g'
worked for me. Though I don’t know why.

Why does your script use "tr" and your command example does not?
I was using that “command example” as a command directly on the console but the one in that script wasn’t the direct implementation of the command; in stead I was substituting the input of "$file" to form the command and that's why 'tr' came in.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top