Answers:
මෙම විධාන සහ එම අණ කිරීමට ඕනෑම තර්ක ලෙස පෙනී අංකයක් ෂෙල් විචල්ය: $0වගේ දෙයක්, මෙම විධානය ම වැල අගයක් ඇත script, ./script, /home/user/bin/scriptහෝ කුමන. ඕනෑම තර්ක ලෙස පෙනී "$1", "$2", "$3"හා ඒ නිසා. තර්ක ගණන ෂෙල් විචල්යයේ "$#"ඇත.
මෙය සමඟ ගනුදෙනු කිරීමේ පොදු ක්රමවලට ෂෙල් විධාන getoptsසහ shift. getoptsසී getopt()පුස්තකාල ශ්රිතය වගේ. වෙත , වෙත , සහ shiftයනාදියෙහි අගය ගෙන $2යයි ; අඩු වේ. කේතය වටිනාකම දෙස අවසන් වේ භාවිතා දේවල්, ... යනු ක්රියාමාර්ග තීරණය කිරීම සඳහා, සහ පසුව කරන්නේ ගමන් ඊළඟ තර්කය කිරීමට. එය කවදා හෝ විමසා බැලිය යුතු අතර සමහර විට .$1$3$2$#"$1"caseesacshift$1$1$#
සම්මත අංකය $nකොතැනද nයන්න සමඟ ඔබට සම්මත තර්ක වෙත ප්රවේශ විය හැකිය 1, 2, 3, .... ඔබ වෙනත් ඕනෑම විධානයක් සමඟ තර්ක විතර්ක කරයි.
$ cat myscript
#!/bin/bash
echo "First arg: $1"
echo "Second arg: $2"
$ ./myscript hello world
First arg: hello
Second arg: worldBash ස්ක්රිප්ට් එකක, පරාමිතීන් සැකසීමට පහත දැක්වෙන ස්ක්රිප්ට් භාවිතා කිරීමට මම පෞද්ගලිකව කැමතියි:
#!/bin/bash
helpFunction()
{
   echo ""
   echo "Usage: $0 -a parameterA -b parameterB -c parameterC"
   echo -e "\t-a Description of what is parameterA"
   echo -e "\t-b Description of what is parameterB"
   echo -e "\t-c Description of what is parameterC"
   exit 1 # Exit script after printing help
}
while getopts "a:b:c:" opt
do
   case "$opt" in
      a ) parameterA="$OPTARG" ;;
      b ) parameterB="$OPTARG" ;;
      c ) parameterC="$OPTARG" ;;
      ? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
   esac
done
# Print helpFunction in case parameters are empty
if [ -z "$parameterA" ] || [ -z "$parameterB" ] || [ -z "$parameterC" ]
then
   echo "Some or all of the parameters are empty";
   helpFunction
fi
# Begin script in case all parameters are correct
echo "$parameterA"
echo "$parameterB"
echo "$parameterC"මෙම ව්යුහය සමඟ, අපි පරාමිතීන්ගේ අනුපිළිවෙල මත රඳා නොසිටිමු. එසේම, පරාමිතීන් වැරදි ලෙස අර්ථ දක්වා ඇති සෑම අවස්ථාවකම උපකාරක කාර්යය මුද්රණය කෙරේ. අපට හැසිරවීමට විවිධ පරාමිතීන් සහිත ස්ක්රිප්ට් ගොඩක් ඇති විට එය ඉතා ප්රයෝජනවත් වේ. එය පහත පරිදි ක්රියා කරයි:
$ bash myscript -a "String A" -b "String B" -c "String C"
String A
String B
String C
$ bash myscript -a "String A" -c "String C" -b "String B"
String A
String B
String C
$ bash myscript -a "String A" -c "String C" -f "Non-existent parameter"
myscript: illegal option -- f
Usage: myscript -a parameterA -b parameterB -c parameterC
    -a Description of what is parameterA
    -b Description of what is parameterB
    -c Description of what is parameterC
$ bash myscript -a "String A" -c "String C"
Some or all of the parameters are empty
Usage: myscript -a parameterA -b parameterB -c parameterC
    -a Description of what is parameterA
    -b Description of what is parameterB
    -c Description of what is parameterC$/shellscriptname.sh argument1 argument2 argument3 ඔබට එක් ෂෙල් ස්ක්රිප්ටයක ප්රතිදානය තවත් ෂෙල් ස්ක්රිප්ටයකට තර්කයක් ලෙස යැවිය හැකිය.
$/shellscriptname.sh "$(secondshellscriptname.sh)"ෂෙල් ස්ක්රිප්ට් තුළ ඔබට $1පළමු තර්කය සහ $2දෙවන තර්කය වැනි සංඛ්යා සමඟ තර්ක වලට ප්රවේශ විය හැකිය .
ආකෘති පත්රය
$ ./script.sh "$@" සඳහා වඩාත් පහසු වේ argv. ආග් පරිසීමකය සුදු අවකාශය, නමුත් වෙනස් කළ හැකිය. මතක තබා ගන්න එපා. ඉන්පසු භාවිතා කරන්න
 $1, $2, shift, if [ $# -ne 3 ] ප්රවාහ පාලනය කිරීමට. case ... esacකැමැත්තක් ප්රමාණවත් නම් මම සාමාන්යයෙන් getopts වැලඳ ගන්නේ නැත .
ෂෙල් පිටපතෙහි; එය විචල්ය නාමය $ 1 බවට පත්වේ. දෙවන වචනය විචල්ය නාමය $ 2 බවට පත්වේ.
cat << 'EOF' > test
echo "First arg: $1"
echo "Second arg: $2"
echo "List of all arg: $@"
EOF
sh test hello worldHttp://heirloom.sourceforge.net/sh/sh.1.html හි ඇති ෂෙල් (ෂ) අත්පොතෙන් තවත් බොහෝ දේ සොයාගත හැකිය
getopt()යනු අතිශයින්ම ස්ථාපිත ප්රමිතියකි, නමුත්getoptක්රියාත්මක කළ හැකි දේ ඩිස්ට්රෝ / වේදිකාව හරහා සමාන නොවේ. මම දැන් සම්පූර්ණයෙන්ම පරිවර්තනය කළgetoptsපරිශීලකයෙක්, එය පොසික්ස් ප්රමිතියක් බැවින්. ඒ සමඟ විශාල වැඩdashමා වඩාත් කැමති තිර රචනය ෂෙල් වන, ද