$@ is not "$@"

when you want to pass multiple parameters through you shell script, you use $@

#! /bin/sh
echo $@

and then execute this file:

./script1 hello world

the script will prints “Hello world”

But be ware, $@ is not “$@” !!

The story is, I wrote some Java file that accepts 1 argument from the command line, such like this:

public class SayHello{
public static void main(String[] args){
if (args.length != 1){
System.out.println("Usage: SayHello ");
// do other staff here

I have wrapped this program in a shell file “sayHello.sh”:

#! /bin/sh
java SayHello $@

But the result was unexpected, as when I run with this command:

./sayHello.sh "Mohammed Hewedy"

I got

Usage: SayHello

I found the problem in the shell file, that I should use “$@” instead of $@
So, the script should be:

#! /bin/sh
java SayHello "$@"

About SoCRaT

Systems Engineer, OSS & Linux Geek
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s