Bash 'shopt' doubt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash 'shopt' doubt
# 1  
Old 10-15-2008
Bash 'shopt' doubt

Hi,

I am using bash shell's extended pattern matching.
What tweak the following code needs in order to get the expected output?

Code:
shopt -s extglob
f="a@b@_c@d@_e"
echo "${f/@(@|@_)/__}"

My expected output is:
a__b__c__d__e

but the actual output is:
a__b@_c@d@_e
# that is, how to make the change global as like echo $f | sed 's/@\|@_/__/g'

Last edited by royalibrahim; 10-15-2008 at 10:35 AM..
# 2  
Old 10-15-2008

bash's extended pattern matching only works on filename expansion, not on parameter expansion.
# 3  
Old 11-10-2008
bash parameter expansion

In bash parameter expansion, do we have any such syntax as below?
Code:
echo "${!var*}"

consider, var is a variable previously set to some arbitrary string value
# 4  
Old 11-10-2008

What do you want it to do?

I suggest that you read the Parameter Expansion section of the bash man page.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Shopt -s histappend

What is the point of this? Whenever I close my shell it appends to the history file without adding this. I have never seen it overwrite my history file. # When the shell exits, append to the history file instead of overwriting it shopt -s histappend (3 Replies)
Discussion started by: cokedude
3 Replies

2. UNIX for Beginners Questions & Answers

Doubt

in my shell script requirement is to search and replace the file with variable so i use the following command sed -i "s/abc/$SCHEMA/g" table.sql later when the script runs sqlplus username/pwd@Table& this & is not letting the variable to replace the value inside the file .please let me know... (1 Reply)
Discussion started by: bhuvan1
1 Replies

3. Red Hat

Doubt

How to create a file with specific size in RHEL6 (1 Reply)
Discussion started by: Sashi Kanth A
1 Replies

4. Shell Programming and Scripting

Bash shell scripting doubt

Hello All, I am setting up a cron job, where i am calling a shell script to make few builds. I got struck at a point, need some expert inputs to proceed further. The script is categorized in 5 parts and in the last part while building software it asks for few questions like:- 1. Build mode... (4 Replies)
Discussion started by: sahil_jammu
4 Replies

5. UNIX for Dummies Questions & Answers

Doubt

Hi , Struck with one basic question. Iam expecting word count of 4 where "wc" is showing as 5 . # echo "abcd" | wc 1 1 5 # echo abcd | wc 1 1 5 (5 Replies)
Discussion started by: penchal_boddu
5 Replies

6. Shell Programming and Scripting

Doubt??

I jus want to know the meaning of the below command line(exclamation following that re-direction) sqlplus -s `cat /home/sample.txt` <<! Thanks!! (1 Reply)
Discussion started by: nohup
1 Replies

7. Shell Programming and Scripting

shopt -s nullglob

Hi, I am using BASH. In a directory there are files that match either of the following 2 patterns: *.L1A_AC* or S*.L1A_MLAC* I would like to write a script that will include a for loop, where for each file in the directory, a certain function will be performed. For example: for FILE in... (4 Replies)
Discussion started by: msb65
4 Replies

8. Shell Programming and Scripting

colors in BASH, doubt with script

I was trying to see all combinations of foreground and background colors in BASH. This works fine for me, echo -e '\E[37;46m TEXT' but when I tried the below script, the variables i and j do not expand. #!/bin/sh for i in `seq 30 37` # foreground do for j in `seq 40... (4 Replies)
Discussion started by: jaduks
4 Replies

9. Shell Programming and Scripting

Bash scripting doubt

i need to check if any user has logged-in more than once in different terminals and then print the count of those login, so i wrote this command, who -H | wc -l but i feel its not accurate , something is wrong ,i have been trying for a long time by trial n error to solve it, but i need... (2 Replies)
Discussion started by: xiphias
2 Replies
Login or Register to Ask a Question