-4

Hi i have a script script.sh which asks to pass a value at the time of execution such as 1 for backup 2 for copy 3 for print. In which i have to pass a value through command line. I just want to pass those values automatically at the time of execution of the shell file. Please provide a solution.

  • 1
    What have you tried? Scripts accepting parameters or options on the command line are completely standard and it's easy to find tons of examples of that. "Please provide a solution.", in addition to being rude, is not how this site works. – Celada Dec 24 '16 at 18:55
  • 1
    Incidentally, I would not recommend something like "1 for backup 2 for copy" etc... Why not "backup for backup, copy for copy", etc... Easier to remember, yes? – Celada Dec 24 '16 at 18:56
  • The question is not clear. You can't pass a command line argument at any other time than at the time of execution. Please reformulate and give examples. – Kusalananda Dec 24 '16 at 22:35
0

From your comments, I deduce you are expecting your script to behave like a complex daemon, which wold invoke itself programmatically.

I think you should write another script to manage the level of automation you require. Said script wold invoke the one you have, with the logic you require

  • do u plz suggest. the syntax under the script – PIyu Dec 26 '16 at 12:45
  • No. It is not clear what you want to do. Be much more specific – Bruno9779 Dec 26 '16 at 14:54
-3

In bash, you can do:

alias script.sh='script.sh 1'

To always run script.sh 1 when script.sh is typed.

  • but if I want to pass 2 and 3 automatically after a certain period? – PIyu Dec 24 '16 at 19:14
  • 1
    aliases which have the same name as their underlying commands tend to confuse everyone. it works when I try it at the command line but doesn't work in a script. – icarus Dec 24 '16 at 19:30
  • @icarus Well, computers are confusing generally. – DepressedDaniel Dec 24 '16 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.