Skip to main content
added 31 characters in body
Source Link
Fedja
  • 125
  • 2
  • 10

I have this variable, and I want to remove both prefix and suffix:

var="abcde"
echo "${${var#a}%e}" 

I tried this snippet in zsh, and it works properly - returns bcd. It uses pattern matching (prefix and suffix). Although, when I run it in posix compliant shell script (the reason I'm using pattern matching instead of bash string manipulation), I get output bad substitution.

What is the matter? Must I make another variable to store "${var#a}" into or can I do it in one line? I want posix compliant script.

I have this variable, and I want to remove both prefix and suffix:

var="abcde"
echo "${${var#a}%e}" 

I tried this snippet in zsh, and it works properly - returns bcd. It uses pattern matching (prefix and suffix). Although, when I run it in posix compliant shell script (the reason I'm using pattern matching instead of bash string manipulation), I get output bad substitution.

What is the matter? Must I make another variable to store "${var#a}" into or can I do it in one line?

I have this variable, and I want to remove both prefix and suffix:

var="abcde"
echo "${${var#a}%e}" 

I tried this snippet in zsh, and it works properly - returns bcd. It uses pattern matching (prefix and suffix). Although, when I run it in posix compliant shell script (the reason I'm using pattern matching instead of bash string manipulation), I get output bad substitution.

What is the matter? Must I make another variable to store "${var#a}" into or can I do it in one line? I want posix compliant script.

edited body
Source Link
Fedja
  • 125
  • 2
  • 10

I have this variable, and I want to remove both prefix and suffix:

var="abcde"
echo "${${var#a}%e}" 

I tried this snippet in bashzsh, and it works properly - returns bcd. It uses pattern matching (prefix and suffix). Although, when I run it in posix compliant shell script (the reason I'm using patterpattern matching instead of bash string manipulation), I get output bad substitution.

What is the matter? Must I make another variable to store "${var#a}" into or can I do it in one line?

I have this variable, and I want to remove both prefix and suffix:

var="abcde"
echo "${${var#a}%e}" 

I tried this snippet in bash, and it works properly - returns bcd. It uses pattern matching (prefix and suffix). Although, when I run it in posix compliant shell script (the reason I'm using patter matching instead of bash string manipulation), I get output bad substitution.

What is the matter? Must I make another variable to store "${var#a}" into or can I do it in one line?

I have this variable, and I want to remove both prefix and suffix:

var="abcde"
echo "${${var#a}%e}" 

I tried this snippet in zsh, and it works properly - returns bcd. It uses pattern matching (prefix and suffix). Although, when I run it in posix compliant shell script (the reason I'm using pattern matching instead of bash string manipulation), I get output bad substitution.

What is the matter? Must I make another variable to store "${var#a}" into or can I do it in one line?

Source Link
Fedja
  • 125
  • 2
  • 10

Pattern match both suffix and prefix in shell script

I have this variable, and I want to remove both prefix and suffix:

var="abcde"
echo "${${var#a}%e}" 

I tried this snippet in bash, and it works properly - returns bcd. It uses pattern matching (prefix and suffix). Although, when I run it in posix compliant shell script (the reason I'm using patter matching instead of bash string manipulation), I get output bad substitution.

What is the matter? Must I make another variable to store "${var#a}" into or can I do it in one line?