According to this answer ...
A command is split into an array of strings named arguments. Argument 0 is (normally) the command name, argument 1, the first element following the command, and so on.
$ ls -la /tmp /var/tmp arg0 = ls arg1 = -la arg2 = /tmp arg3 = /var/tmp
Would it be possible to print out each argument ... let say with echo.
I've been using echo $@
and echo $0 $1 $2 $3
right after executing ls -la /tmp /var/tmp
command but didn't really work.
I also tried this without > /dev/null
but didn't work as well. (I'm getting exactly similar output as below)
user@linux:~$ ls -la /tmp /var/tmp > /dev/null
user@linux:~$ echo $@
user@linux:~$
user@linux:~$ ls -la /tmp /var/tmp > /dev/null
user@linux:~$ echo $0
bash
user@linux:~$
user@linux:~$ ls -la /tmp /var/tmp > /dev/null
user@linux:~$ echo $1
user@linux:~$
user@linux:~$ ls -la /tmp /var/tmp > /dev/null
user@linux:~$ echo $0 $1 $2 $3
bash
user@linux:~$
Desired Output
I'm expecting to see the following output on my terminal screen after executing ls -la /tmp /var/tmp
Input
ls -la /tmp /var/tmp
Output
arg0 = ls
arg1 = -la
arg2 = /tmp
arg3 = /var/tmp
ls -la /tmp /var/tmp
-- the command and arguments -- but then proceed to show your interactive shell (with itsecho
commands) expecting to see similar argument expansions. But your only commands are the ones you're executing. – Jeff Schaller Jul 04 '19 at 01:19ls -la /tmp /var/tmp
) by producing something visible on my screen with echo.e.g.
– Jul 04 '19 at 01:29arg0 is ls
,arg1 is -la
and so onecho !:1
,echo !:2
etc. – steeldriver Jul 04 '19 at 01:41set -x
. Runset -x
and thenls -la /tmp /var/tmp
and you will see thels
command split into its arguments as you expect. Runset +x
to remove this debugging output. – terdon Jul 04 '19 at 14:55