...
Bash - . , -, Bash . script , .
$ set -x
set -x
$ foo=bar
+ foo=bar
$ echo "$foo"
+ echo bar
bar
$ set +x
set -x . , . , foo=bar, echo $foo. echo $foo. echo $foo bar. echo , , bar ( $foo).
. , . echo *.txt, echo *.txt, .
, script:
#! /bin/sh
if [[ $1 = "*" ]]
then
echo "The first argument was '*'"
else
"I was passed in $# parameters"
fi
script:
$ test.sh *
I was passed in 24 parameters
? script a *? . * , . script *. :
$ test.sh '*'
The first argument was '*'
-. ( , ).
, , , :
$ test.sh '$foo'
:
if [[ $1 != ${1#$} ]]
then
echo "The first parameter is the variable '$1'"
fi
${1#$} , ${var#pattern}. pattern $var. $1 $, . :
if [[ $foo != foo ]]
.
, :
- First, you must stop shell interpretation from your variable. This means that you need to use single quotes around the name.
- You need to use pattern matching to make sure that the first parameter starts with
$. - Once you do this, you can use your c variable
${$1}in the script.
source
share