How to pass arguments in a shell script?
Hello,
i am getting use to use shell scripts for linux. How do I pass arguments? Basically I found a shell where I can compare files and append the ones not found: if ! diff file1 file2 > /dev/null; then echo diff else echo not_diff fi But I want to replace file1 and file2 as two arguments...how can I do this? Thanks |
Hi,
$1, $2, $3 etc represent the arguments give to the script at run time. somescript.sh foo bar foobar Inseide the somescript.sh script foo is assigned to $1, bar to $2, foobar to $3. Although you can work with $1, $2 etc inside your script it is wise to use variables that are human readable. Code:
#!/bin/bash Do take a look at the Bash guides that are around. Here are 2: Bash Guide for Beginners Advanced Bash-Scripting Guide Hope this helps. |
All times are GMT -5. The time now is 06:30 AM. |