what is $@

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers what is $@
# 1  
Old 09-12-2008
what is $@

I saw this in a script. Just curious to know what $@ is.

${JAVA_HOME}/bin/java -showversion -Duser.language=en -DP4ClassLoad=P4Connection -Dp4Cache=clean -jar go.jar $@
# 2  
Old 09-12-2008
It expands to the command-line parameters passed to the script. However, it's wrong; it should be in double quotes, like "$@"

vnix$ cat >script
echo args: "$@"
for f in "$@"; do echo "arg: $f"; done
vnix$ sh ./script foo bar baz
args: foo bar baz
arg: foo
arg: bar
arg: baz

Last edited by era; 09-12-2008 at 07:20 AM.. Reason: Add sample script
This User Gave Thanks to era For This Post:
# 3  
Old 09-12-2008
Hi Roshni,

$@ is used to pass arguments to the script.

for example:


cat "$@"

if you execute the script by saying sample.sh file1 file2 then it will give output as

cat "file1" "file2"

so acts to take arguments to the script.

Last edited by subhendu81; 09-12-2008 at 07:30 AM.. Reason: for better clarification
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question

Featured Tech Videos