Require command line argument for script to run [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm trying to require a script to only run if the command line argument provided is a specific text file called dailyUserProcs.20181203 in the same directory as the script. I am also running Putty.



Currently I am requiring any input to run the script, shown below.



if [ -z "$1" ] then
echo" No argument"
exit 1
fi









share|improve this question















closed as off-topic by Jeff Schaller, Sparhawk, G-Man, RalfFriedl, JigglyNaga Dec 5 at 10:47


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Sparhawk, RalfFriedl, JigglyNaga
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    Why require that specific argument if it's static?
    – Jeff Schaller
    Dec 4 at 23:21










  • Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
    – SoggyJ
    Dec 4 at 23:31










  • So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
    – Jeff Schaller
    Dec 5 at 0:14










  • Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
    – SoggyJ
    Dec 5 at 0:31














up vote
0
down vote

favorite












I'm trying to require a script to only run if the command line argument provided is a specific text file called dailyUserProcs.20181203 in the same directory as the script. I am also running Putty.



Currently I am requiring any input to run the script, shown below.



if [ -z "$1" ] then
echo" No argument"
exit 1
fi









share|improve this question















closed as off-topic by Jeff Schaller, Sparhawk, G-Man, RalfFriedl, JigglyNaga Dec 5 at 10:47


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Sparhawk, RalfFriedl, JigglyNaga
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    Why require that specific argument if it's static?
    – Jeff Schaller
    Dec 4 at 23:21










  • Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
    – SoggyJ
    Dec 4 at 23:31










  • So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
    – Jeff Schaller
    Dec 5 at 0:14










  • Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
    – SoggyJ
    Dec 5 at 0:31












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to require a script to only run if the command line argument provided is a specific text file called dailyUserProcs.20181203 in the same directory as the script. I am also running Putty.



Currently I am requiring any input to run the script, shown below.



if [ -z "$1" ] then
echo" No argument"
exit 1
fi









share|improve this question















I'm trying to require a script to only run if the command line argument provided is a specific text file called dailyUserProcs.20181203 in the same directory as the script. I am also running Putty.



Currently I am requiring any input to run the script, shown below.



if [ -z "$1" ] then
echo" No argument"
exit 1
fi






linux bash arguments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 4 at 23:22

























asked Dec 4 at 23:19









SoggyJ

62




62




closed as off-topic by Jeff Schaller, Sparhawk, G-Man, RalfFriedl, JigglyNaga Dec 5 at 10:47


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Sparhawk, RalfFriedl, JigglyNaga
If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Jeff Schaller, Sparhawk, G-Man, RalfFriedl, JigglyNaga Dec 5 at 10:47


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Sparhawk, RalfFriedl, JigglyNaga
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 2




    Why require that specific argument if it's static?
    – Jeff Schaller
    Dec 4 at 23:21










  • Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
    – SoggyJ
    Dec 4 at 23:31










  • So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
    – Jeff Schaller
    Dec 5 at 0:14










  • Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
    – SoggyJ
    Dec 5 at 0:31












  • 2




    Why require that specific argument if it's static?
    – Jeff Schaller
    Dec 4 at 23:21










  • Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
    – SoggyJ
    Dec 4 at 23:31










  • So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
    – Jeff Schaller
    Dec 5 at 0:14










  • Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
    – SoggyJ
    Dec 5 at 0:31







2




2




Why require that specific argument if it's static?
– Jeff Schaller
Dec 4 at 23:21




Why require that specific argument if it's static?
– Jeff Schaller
Dec 4 at 23:21












Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
– SoggyJ
Dec 4 at 23:31




Honestly I agree there is no reason for it, but sadly this is for a class assignment and is required.
– SoggyJ
Dec 4 at 23:31












So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
– Jeff Schaller
Dec 5 at 0:14




So you've learned about test ([) and $1... what did you try for comparing $1 to a string?
– Jeff Schaller
Dec 5 at 0:14












Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
– SoggyJ
Dec 5 at 0:31




Wow, thanks for the comment. Just figured it out after reading your comment. Appreciate it!
– SoggyJ
Dec 5 at 0:31










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










To test if a file exists, use -f.
To test if two strings are equal, use == (and similarly not equal is !=).
To negate something, use !.
To logical or two tests, use ||.
Putting this all together, you get



if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
echo Invalid Argument
exit 1
fi
echo Argument exists and is correct
# ... rest of code


This can all be found by typing info test, and reading the documentation.






share|improve this answer



























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    To test if a file exists, use -f.
    To test if two strings are equal, use == (and similarly not equal is !=).
    To negate something, use !.
    To logical or two tests, use ||.
    Putting this all together, you get



    if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
    echo Invalid Argument
    exit 1
    fi
    echo Argument exists and is correct
    # ... rest of code


    This can all be found by typing info test, and reading the documentation.






    share|improve this answer
























      up vote
      0
      down vote



      accepted










      To test if a file exists, use -f.
      To test if two strings are equal, use == (and similarly not equal is !=).
      To negate something, use !.
      To logical or two tests, use ||.
      Putting this all together, you get



      if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
      echo Invalid Argument
      exit 1
      fi
      echo Argument exists and is correct
      # ... rest of code


      This can all be found by typing info test, and reading the documentation.






      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        To test if a file exists, use -f.
        To test if two strings are equal, use == (and similarly not equal is !=).
        To negate something, use !.
        To logical or two tests, use ||.
        Putting this all together, you get



        if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
        echo Invalid Argument
        exit 1
        fi
        echo Argument exists and is correct
        # ... rest of code


        This can all be found by typing info test, and reading the documentation.






        share|improve this answer












        To test if a file exists, use -f.
        To test if two strings are equal, use == (and similarly not equal is !=).
        To negate something, use !.
        To logical or two tests, use ||.
        Putting this all together, you get



        if [ ! -f "$1" ] || [ "$1" != "dailyUserProcs.20181203" ]; then
        echo Invalid Argument
        exit 1
        fi
        echo Argument exists and is correct
        # ... rest of code


        This can all be found by typing info test, and reading the documentation.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 5 at 2:22









        SmoothJazz

        161




        161












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay