0

consider there a directory called hello world in the current directory. Yes the directory has a space in it. For sake of example lets say it has a file called f1.txt.

ls 'hello world'

will print

f1.txt

but

a="ls 'hello world'"
$a

say

ls: cannot access ''\''hello': No such file or directory
ls: cannot access 'world'\''': No such file or directory

So the question is how to make ls list the directory hello world. Basically how to this

a="1 2"
b="ls $a"
$b

to actually list the contents of the folderhello world

PS: I don't want to do

a="1 2"
ls $a

I want to store it and only then run it

Samarth S
  • 103

1 Answers1

0
francois@zaphod:~$ mkdir "hello world"
francois@zaphod:~$ touch "hello world"/{a,b,c}
francois@zaphod:~$ a="ls 'hello world'"
francois@zaphod:~$ eval "$a"
a  b  c
francois@zaphod:~$ 

eval your variable will execute the variable as a text of the command you need to run

francois P
  • 1,219