Search code examples
shellunix

What do you call "-a" or any letter after hypen/dash (-) in Shell Scripting?


Below is the code in my project I am trying to understand. Anyone can interpret what is it called? (-s and -a)

if [***-s*** $A ***-a -s*** $B] 

then ..

else ..

fi

Also, Is there a dictionary wherein all of - is listed and its use?

Google search does not exactly match the information I need. Since I don't know what's called. Please help!

Thank you in advance!


Solution

  • You are looking for conditional expressions. Assuming you are using bash, you can look at the section 6.4 Bash Conditional Expressions of the Bash Reference Manual.

    -a file
    True if file exists.
    
    -b file
    True if file exists and is a block special file.
    
    -c file
    True if file exists and is a character special file.
    
    -d file
    True if file exists and is a directory.
    
    -e file
    True if file exists.
    
    -f file
    True if file exists and is a regular file.
    
    -g file
    True if file exists and its set-group-id bit is set.
    
    -h file
    True if file exists and is a symbolic link.
    
    -k file
    True if file exists and its "sticky" bit is set.
    
    [...]
    
    

    See the documentation cited above for the full list.