I need to create a script that uses an 'if' command that checks whether there is exactly one argument. If there is more than one argument, I need it to echo “Usage: give exactly 1 argument, the string to be looked for” and then exit immediately.
            Asked
            
        
        
            Active
            
        
            Viewed 43 times
        
    1 Answers
1
            
            
        Welcome to Stackoverflow.
This should do the trick:
if [ "$#" -gt 1 ]; then
    echo "Usage: give exactly 1 argument, the string to be looked for"
    exit 0
else
   echo the expected processing happens in this section of this code
fi
 
    
    
        Mamun
        
- 2,322
- 4
- 27
- 41
