Search Results

Search found 1 results on 1 pages for 'user2889968'.

Page 1/1 | 1 

  • How can I set a default value when incorrect/invalid input is entered in Unix?

    - by user2889968
    i want to set the value of inputLineNumber to 20. I tried checking if no value is given by user by [[-z "$inputLineNumber"]] and then setting the value by inputLineNumber=20. The code seems to be working correct when no value is given but I also receive ./t.sh: [-z: not found as message on the console. Is there some way to not print this message. Here's my full script as well. #!/bin/sh cat /dev/null>copy.txt echo "Please enter the sentence you want to search:" read "inputVar" echo "Please enter the name of the file in which you want to search:" read "inputFileName" echo "Please enter the number of lines you want to copy:" read "inputLineNumber" [[-z "$inputLineNumber"]] || inputLineNumber=20 cat /dev/null > copy.txt for N in `grep -n $inputVar $inputFileName | cut -d ":" -f1` do LIMIT=`expr $N + $inputLineNumber` sed -n $N,${LIMIT}p $inputFileName >> copy.txt echo "-----------------------" >> copy.txt done cat copy.txt

    Read the article

1