views:

31

answers:

2

I am writing a simple shell script that fetches output from one command uses it in another.

 app=$(./twiddle.sh  -u $1 -p $2 query jboss.web.deployment:* | grep $3)
 doop=$(./twiddle.sh -u $1 -p $2 invoke jboss.system:MainDeployer $4 $app)

++ ./twiddle.sh -u admin -p password invoke jboss.system:MainDeployer stop $'jboss.web.deployment:war=worker.war,id=1518231766\r'

I see in the above commands that the app is coming of value:

$'jboss.web.deployment:war=worker.war,id=1518231766\r'

But if I do echo $app then I am not seeing the quotes and \r appended, How can I ensure app is sent without quotes as an input to another command?. I am not sure where the problem is - I cannot see this as the output when I execute the commands outside of shell.

Thanks for any help.

A: 
doop=$(./twiddle.sh -u $1 -p $2 invoke jboss.system:MainDeployer $4 "$app")

You should use echo with quotes if you don't want the contents be interpreted by the shell. If you don't want characters like ' be interpreted too, use printf: printf '%s' "$app"

Lekensteyn
No adding quotes did not remove the problem.
Anna
Did you try the second thing, with printf?Like this:doop=$(./twiddle.sh -u $1 -p $2 invoke jboss.system:MainDeployer $4 "``printf '%s' "$app"``")
Lekensteyn
A: 

sed will work nicely for this:

sh  -u $1 -p $2 query jboss.web.deployment:* | grep $3 | sed 's/\'//g' | sed 's/\r//g'
ennuikiller
It worked by doing this: app=`echo $app | sed 's/\r//g'`
Anna
glad you got working....
ennuikiller