Given:
myvar=Hello
echo $myvar-> ShowsHello(fine so far)echo $myvar#world-> showsHello#world(why? I thought it would complain that here is no such variable calledmyvar#world)echo ${myvar#world}-> shows justHello(again, why?)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The second case splits up into three parts:
Part 1 is the command, part 2 is a parameter, and part 3 is a string literal. The parameter stops on
rsince the#can’t be part of the variable name (#’s are not allowed in variable names.)The shell parser will recognise the start of a parameter name by the
$, and the end by any character which cannot be part of the variable name. Normally only letters, numbers and underscores are allowed in a variable name, anything else will tell the shell that you’re finished specifying the name of the variable.All of these will print out
$myvarfollowed by six literal characters:If you want to put characters which can be part of a parameter directly after the parameter, you can include braces around the parameter name, like this:
which prints out:
Your third case is substring removal, except without a match. To get it to do something interesting, try this instead:
which just prints
World.