-2

Need help understanding this script I cannot figure out what the -z condition means for first line then the -z with the "$1" in the if statement Here is the script:

while [ -z "$USERNAME" ]
do
if [ -z "$1" ]
    then
        unset ans
 unset USER
 echo "What is the username you would like to add?"
 read USER
 echo "Is" $USER " the correct username? [y/n]"
 read ans
 case "$ans" in
     y|Y|yes|Yes|YES)
  USERNAME=$USER

;;

  • 1
    Have you looked for the string `-z` in the `bash` man page? – chepner Feb 08 '18 at 21:31
  • 1
    `[` is a synonym for the `test` builtin. See: `help test | grep -- -z` – Cyrus Feb 08 '18 at 21:33
  • BTW, avoid all-caps names for your own variables -- those names are used for variables with meaning to the operating system or shell; sharing that namespace for user-defined variables means you can overwrite them by mistake. See http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html, fourth paragraph, reserving lowercase names for application use. – Charles Duffy Feb 08 '18 at 21:47

1 Answers1

0
-z
string is null, that is, has zero length

Full info regarding test in bash

Please see special variables for more info regarding what $1.

Arguments passed to the script from the command line [1] : $0, $1, $2, $3 . . .

$0 is the name of the script itself, $1 is the first argument
  • See [How to Answer](https://stackoverflow.com/help/how-to-answer), particularly the section "Answer Well-Asked Questions", particularly the bullet regarding questions which "...have already been asked and answered many times before". – Charles Duffy Feb 08 '18 at 21:44
  • (Also, a single StackOverflow question which contains two distinct language questions is covered by the bullet regarding questions which "request answers to multiple questions"). – Charles Duffy Feb 08 '18 at 21:45