shell - How do I pass an empty string with double quotes to a bash script? -
I am trying to write a script which, as an additional argument on the command line, accepts an empty string with double quotes Will do I want the script to pass those arguments with double-quoted blank string, if it is provided, but instead the command interpreter is considered such as an empty string and the quotation marks are removed is. Is there any way of doing it?
As a simple example, I have to be in the file script. Sh:
#! / Bin / bash / home / myapp $ 1 $ 2 If I run at the prompt:
$ ./script.sh arg1 "" < / Code> The script executes only "/ home / myapp arg1" , but the second argument ("") misses / looks Comes. I want to preserve the empty string and execute it instead: / home / myapp arg1 ""
You can find out how many positional parameters were given in your script, for example, if it is 2 or more, then you know that $ 2 Something was passed for, even if $ 2 is empty (quotation extract by calling shell has been removed). If the parameter was passed, but empty: in this case ( echo ) applies the following logic to the program, and " " passes #! / Bin / bash if [$ # -ge 2]; So if ["$ 2"]; So arg2 = "$ 2" and arg2 = '"" eef "$ 1 $ arg2" elif [$ # == 1]; Then "$ 1" should be imported Output:
$ ./args.sh aa $ ./args.sh A "$ ./args. Sh1A1 $
Comments
Post a Comment