0

see i want to use source command in my shell script. Now when i type source on terminal it shows like

-bash: source: filename argument required
source: usage: source filename [arguments]

now when i use this in my shell script like this

#!/bin/sh
source

and save as test.sh

and run then get like this

./test.sh: 2: source: not found

How to solve this problem?

3
  • 1
    Source requires an argument. What do you expect it to do without one? Commented Aug 3, 2012 at 13:34
  • i know it but here problem is source command is not finding...if i give argument still it will not work.. Commented Aug 3, 2012 at 13:35
  • source file in bash or csh is a command that reads commands from file into the current shell (either script or interactive session). The more portable version of this is the dot command . file. This is supported on all common unix shells. Commented Aug 3, 2012 at 13:38

1 Answer 1

5

You run your script with sh, not with bash. source does not exist in plain sh, but you can use . instead, it means the same thing.

#!/bin/sh
. /path/to/other/script
function_defined_in_other_script
Sign up to request clarification or add additional context in comments.

6 Comments

Indeed, use . file to make it work across different shells.
@HenkLangeveld: . does not work in dash (the default sh on Ubuntu). Neither is it documented in its manpage.
$ . ./test_dot.sh Results in This is test_dot.sh, called from dash on my vagrant linux box. (file contains echo This is test_dot.sh, called from $0 )
@HenkLangeveld: my mistake. Tried with a file which did exist system wide as well … – still, I cannot find it in the manpage.
It's in man dash, three paragraphs down in the Builtins section
|

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.