Register
It is currently Tue Sep 30, 2014 5:55 pm

$vars in sed causing issue


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Sun Jul 14, 2013 11:50 pm   

Joined: Mon Jul 01, 2013 7:24 pm
Posts: 19
hi, I am hoping someone can tell me what is wrong with this sed command. I have been looking at it on and off for a few days, tinkering with it and cannot get ot to work. The second command immediately following works fine, but the first pukes back an error with the 'sed' command.

Also when I try to use $HOME instead of the literal path I get the same error. So I am having a problem properly calling $vars in the sed command; however, the $var $devId works find in the second version of the command.

this command fails to run, reporting sed (user) error:
Code:
mnt=$(echo "$mnt"|sed -r "s/^(.*)$/\1 ; \/home\/user\/bin\/mnt_intDevs\.sh ${one} ${two} ${three}/")


this command runs fine:
Code:
mnt=$(echo "$mnt"|sed -r "s/^(.*)$/\1 ; \/home\/user\/bin\/$devId/")


I have a feeling the issue is going to be something stupidly obvious. I waited as long as I could, hoping to spot the error, but I am out of ideas. So if someone can lend some advice or a suggestion I would sure appreciate it.


Top
 Profile  
 PostPosted: Mon Jul 15, 2013 11:48 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 549
hi,

what's the exact error message ?
please provide the content of $mnt that causes the message.


Top
 Profile  
 PostPosted: Mon Jul 15, 2013 1:58 pm   

Joined: Mon Jul 01, 2013 7:24 pm
Posts: 19
Quote:
what's the exact error message ?

Code:
sed: -e expression #1, char 54: unknown option to `s'


Quote:
please provide the content of $mnt that causes the message.

this is how the vars are assigned, followed with a call to function 'mntDev':
Code:
one="/dev/sda5"
two="stuffA"
three="_intHdA200Gb"
mntDev


here is function 'mntDev':
Code:
function mntDev {
   if [[ "$hds" == *${cntr}* ]] ; then
      echo "cntr: $cntr   mnt before: $mnt"   #verify           
      echo "one: $one   two: $two   three: $three"   #verify
      #mnt=$(echo "$mnt"|sed -r "s/^(.*)$/\1 ; \/home\/user\/bin\/$devId/")   #this command works fine with devId="mnt_stuffA_intHdA200Gb.sh"
      mnt=$(echo "$mnt"|sed -r "s/^(.*)$/\1 ; \/home\/user\/bin\/mnt_intDevs\.sh ${one} ${two} ${three}/")
   fi
   echo "mnt after: $mnt"   #verify
   ((cntr++))
}


var 'mnt' is then used in another script expecting three user supplied vars, which are of course the content of vars $one, $two and $three


Top
 Profile  
 PostPosted: Mon Jul 15, 2013 4:14 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 549
slashes inside $one (and every special characters for sed inside every variables) have to be protected too!
Code:
one="/dev/sda5"
one="${one//\//\\\/}"
or
Code:
one="\/dev/\sda5"
depending how you get one.


Top
 Profile  
 PostPosted: Tue Jul 16, 2013 2:29 pm   

Joined: Mon Jul 01, 2013 7:24 pm
Posts: 19
Quote:
slashes inside $one (and every special characters for sed inside every variables) have to be protected too!

That worked great! Thanks Watael.

How, though, can I use ENV $VARs then in a 'sed' command like $HOME which do not have any slashes to protect, even though they represent them?

NM: I was too quick with the question without looking longer. Changing the delimter works just fine, like:
Code:
mnt=$(echo "$mnt"|sed -r "s|^(.*)$|\1 ; $HOME/bin/mnt_intDevs\.sh ${one} ${two} ${three}|")


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP