Dhruv Jagetiya Dhruv Jagetiya - 2 years ago 95
Bash Question

Passing argument to command in bash shell script

I was trying to automate a small build process using shell scripting. Build process is basically:

  1. cd /location/to/build.xml

  2. /Path/To/ant release. Run ant with release as argument.

I created a build.sh file which I intend to use as
./build.sh release
to build release version, and my shell script file is:

cd "/Location/To/Build.xml"

I get
ant not a file or command
when I execute this shell file as
./build.sh release
even though the ant file is there.

Also, when I use
. Script runs just fine.

What is the difference between

Answer Source

The different is, when you do "$ANT... $1", shell execute a command called /path/to/ant release, note, it is one command with space as part of command. So command not found.

But if you "$ANT..." "$1" it will execute command /paht/to/ant, and take release as argument/option.

Test with this, you will see:

kent$  "ls -l"
zsh: command not found: ls -l #it thinks a command is "ls(space)-l"

kent$  "ls" "-l"
total xx
<file lists>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download