-1

Running command /bin/sh -c ls, I see:

> /bin/sh -c ls 20190816_212056.png Opera_65.0.3467.78_Setup.exe 20190816_212219.png Opera_66.0.3515.27_Setup.exe 20190816_212344.png opera-stable_60.0.3255.95_amd64.rpm 20191112_134658.jpg opera-stable_62.0.3331.99_amd64.rpm 20200201_175524.jpg opera-stable_63.0.3368.107_amd64.rpm 20200201_175602.jpg opera-stable_65.0.3467.48_amd64.rpm 

When I run /bin/sh -c ls -lh, I see the exact same output as /bin/sh -c ls. The option -lh is not considered at all. Why is that? Am I missing something?

Note

/bin/sh is a symbolic link to bash:

> ls -lh /bin/sh lrwxrwxrwx 1 root root 4 Sep 20 2019 /bin/sh -> bash 
0

1 Answer 1

1

If you want to run a command with spaces inside you need to add "" around it. Otherwise it will just execute ls

Try running /bin/sh -c "ls -lh"

2
  • So, why I see Docker executing /bin/sh -c commands with spaces? Is Docker different? Commented Apr 30, 2021 at 7:01
  • 1
    @user3405291 whatever log you're looking at probably just prints the arguments as is, without quoting or otherwise indicating separate arguments. Commented Apr 30, 2021 at 7:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.