1

I have a list of shell scripts which needs to be run sequentially and they take a different text file as input parameter. I tried to put all the scripts into a file and source the file.

But there is a bash error coming up. What is the best way to do this. My files are:

sh test.sh --dir hello --fname 1.txt --bdt 0318    
sh test.sh --dir hello --fname 2.txt --bdt 0318

Here dirname is the directory fname is filename.

5
  • What is the error you are seeing? Commented Mar 19, 2017 at 4:56
  • bash: source: /usr/bin/test: cannot execute binary file Commented Mar 19, 2017 at 5:00
  • @Inian I included these scripts in a file test and running it as source test Commented Mar 19, 2017 at 5:03
  • Can you run it as source ./test Commented Mar 19, 2017 at 5:04
  • @Inian Its working. Thank you. But i ran the same with just the copy commands in a file and source run it. It worked. Why is not working for shell scripts? Commented Mar 19, 2017 at 5:14

1 Answer 1

1

The source command will:

Read and execute commands from the filename argument in the current shell context. If filename does not contain a slash, the PATH variable is used to find filename.

This behaviour is defined (for ., its alias) by POSIX. So you can put sourceable configuration scripts inside PATH and access them without a qualified path. To access the file you want, give an absolute or relative path instead:

source ./test
Sign up to request clarification or add additional context in comments.

3 Comments

@KattangooriReddy: You can do it, but as a background job it will not affect your running session.
@KattangooriReddy : there is nothing stopping it to work! But it might not change the current shell's behavior.
The problem running on background is that I am connected to remote server through putty so it is disconnecting often and my session is expiring there by halting my source ./test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.