Sunday, May 5, 2024
93
rated 0 times [  93] [ 0]  / answers: 1 / hits: 232813  / 1 Year ago, thu, december 8, 2022, 3:12:29

I am running some script which passing the string argument and I want to do if else statement shown as below:



if [ $1 != '' ] && [ $2 != '' ]
then
do something.....


but it shown Error too many argument. Why?


More From » command-line

 Answers
2

Try using the -z test:



if [ -z "$1" ] && [ -z "$2" ]


From man bash:



-z string
True if the length of string is zero.

[#26173] Saturday, December 10, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eaderitable

Total Points: 368
Total Questions: 117
Total Answers: 111

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
;