0

I want to extract the directory. I have used the below mentioned shell script.

line='create word=/some/directory/name'
dir=${${${line##*=}#"'"}%"'"}

Though, it is working for me, I want to know the working of the 2nd line. How exactly string split occur in the shell scripting.

4
  • What shell? bash: ${${${line##*=}#"'"}%"'"}: bad substitution Commented Mar 1, 2015 at 15:05
  • and ${line##*=} is sufficient: the single quotes are removed by the shell, so they are not part of the value in $line Commented Mar 1, 2015 at 15:06
  • using zsh. I tried using ${line##*=} and echoed the value. The echoed string contained single quotes. I am not sure if these quotes are internally removed while using the string. Commented Mar 1, 2015 at 17:12
  • in zsh echo ${line##*=} does not display any single quotes for me. You must have been doing something different. Commented Mar 1, 2015 at 22:53

1 Answer 1

1

These constructs are known as "Parameter Substitutions".

For example (directly from the Bash documentation):

${var##Pattern} Remove from $var the longest part of $Pattern that matches the front end of $var.

Sign up to request clarification or add additional context in comments.

1 Comment

Since the question is tagged zsh (now), it is best to refer to the zsh documentation since this is an area where zsh is radically different from bash in some respects — zsh allows nested application of parameter substitutions in a way that bash does not. That said, individual steps are equivalent; it is just that you can't do the nested operations in bash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.