Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux/Bash: How to unquote?

Following command

echo 'a b' 'c'

outputs

a b c

But the following

X="'a b' 'c'"
echo $X;

will outout

'a b' 'c'

I am searching a way to unquote $X , so that it will output "a b c" , but without losing the merged 'a b' argument. (= 2 arguments instead of 3, makes no difference for command 'echo', but for other commands like 'cp')

like image 389
Daniel Marschall Avatar asked Aug 08 '11 20:08

Daniel Marschall


2 Answers

Try xargs:

$ echo $x
'a b' 'c'

$ echo $x | xargs ./echo
argc = 3
argv[0] = ./echo
argv[1] = a b
argv[2] = c
like image 68
vanza Avatar answered Oct 08 '22 13:10

vanza


eval echo $x

this will pass a b as first argument and c as the second one

Note: this will actually evaluate arguments, eg:

$ x='$((3+5))'
$ eval echo $x
8

If that's not what you want use @vanza's xargs.

like image 31
Karoly Horvath Avatar answered Oct 08 '22 13:10

Karoly Horvath