Debugging Shell Arguments

laktak

Is there a command like echo that shows the arguments as they were received?

For example echo "a b" c shows a b c

but I would like to see something like "a b" "c".

ilkkachu

You could use printf, e.g.:

$ printf ">%s<\n" "a b" c
>a b<
>c<

Or use whichever separators you like, but note that it doesn't produce shell-style quoted output like set -x does. And it always prints the format string at least once, so printf ">%s<\n" without other arguments produces ><.

Or to get shell-style quoted output in Bash:

$ printf "%q\n" "a b" c
a\ b
c

The downside of %q is that it prefers backslashes instead of quotes, so the output is ugly and harder to read than necessary.

Of course, you could also create an external script to do that, but it might too heavy a solution for your situation:

$ cat args.sh
#/bin/bash
printf "%d args: " "$#"
for x do
    printf "%s " "${x@Q}"   # nicer output than printf %q
done
echo

$ ./args.sh "a b" c
2 args: 'a b' 'c' 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

interactive shell debugging with pycharm

From Dev

Debugging with PyCharm terminal arguments

From Dev

Passing Arguments to Shell Script

From Dev

Pass list of arguments to a command in shell

From Dev

How to validate shell arguments?

From Dev

Convert array to arguments for shell command

From Dev

Convert a string into shell arguments

From Dev

Linking two arguments - Shell Script

From Dev

Set protractor arguments debugging in visual studio code

From Dev

Passing arguments to C++ programme for debugging in VSCode

From Dev

GDB Debugging: Passing arguments using IO redirection

From Dev

Debugging shell scripts with line numbers

From Dev

escape shell arguments in AppleScript?

From Dev

Passing named arguments to shell scripts

From Dev

Print shell arguments in reverse order

From Dev

Reading arguments in shell script

From Dev

Has PyDev an interactive shell (during debugging) as in Komodo?

From Dev

Convert array to arguments for shell command

From Dev

Shell expansion for arguments?

From Dev

Assigning Arguments in Shell Scripts

From Dev

Debugging shell scripts: Syntax checking without executing

From Dev

Shell syntax for redirecting arguments?

From Dev

MongoDB - Shell Scripting - $in arguments not working

From Dev

Loop all arguments in a shell script

From Dev

How to reverse shell arguments?

From Dev

Passing arguments to a shell script

From Dev

Capturing the output of shell DEBUGGING process

From Dev

shell script functions arguments/parameters

From Dev

Debugging C program with two arguments passed