There is a if condition as below
if [ "${1#*-}" = "$1" ]; then
echo "Do something"
fi
But could somebody explain what is the meaning of ${1#*-}
?
It says, “If there is at least one argument ( ${1+ ), then substitute in all the arguments ( “$@” ) preserving all the spaces, etc. within each argument.
$1 is the first command-line argument passed to the shell script. Also, know as Positional parameters. For example, $0, $1, $3, $4 and so on. If you run ./script.sh filename1 dir1, then: $0 is the name of the script itself (script.sh)
From Bash Manual. $0 Expands to the name of the shell or shell script. This is set at shell initialization. If Bash is invoked with a file of commands (see Section 3.8 [Shell Scripts], page 39), $0 is set to the name of that file.
#!/bin/bash The most common shebang is the one referring to the bash executable: #!/bin/bash. Essentially it tells your terminal that when you run the script it should use bash to execute it.
${1#*-}
deletes the shortest match of *-
, a glob-like pattern from $1
variable.
E.g. abcdef-xyz-foo
-> xyz-foo
Your if
check does actually:
if $1 does not contain '-'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With