From: undisclosed on 10 Sep 2009 08:12 Hi , you can continue to work in Bash script by adding the following changes in passwd file present at the path cd /etc/ in passwd file under root change the root:x:0:0:Super-User:/root:/bin/ksh to root:x:0:0:Super-User:/root:/bin/bash rupert;1253510 Wrote: > I've been going through a very good bash scripting tutorial here: > 'Parameter Substitution' > (http://tldp.org/LDP/abs/html/parameter-substitution.html#PSUB2) > > It is based on the Korne-shell (so naturally the she-bang is: #!/bin/ > ksh) > but I want to continue to program in my Borne-again-shell with #!/bin/ > bash > (or #!/bin/sh as I gather ubuntu 8.10 is bash by default). > > #!/bin/bash > #this causes a Bad substitution error... > path_name=/home/bozo/ideas/somestuff > t=${path_name/bozo/clown} #this will fail here... > echo $t > exit 0 > > what is the Bash alternative to do a substitution like this? -- venkatareddy
From: Eric on 10 Sep 2009 21:45 undisclosed wrote: > Hi , > > you can continue to work in Bash script by adding the following > changes in passwd file present at the path cd /etc/ > > in passwd file under root change the > root:x:0:0:Super-User:/root:/bin/ksh > > to root:x:0:0:Super-User:/root:/bin/bash > > rupert;1253510 Wrote: >> I've been going through a very good bash scripting tutorial here: >> 'Parameter Substitution' >> (http://tldp.org/LDP/abs/html/parameter-substitution.html#PSUB2) >> >> It is based on the Korne-shell (so naturally the she-bang is: #!/bin/ >> ksh) >> but I want to continue to program in my Borne-again-shell with #!/bin/ >> bash >> (or #!/bin/sh as I gather ubuntu 8.10 is bash by default). >> >> #!/bin/bash >> #this causes a Bad substitution error... >> path_name=/home/bozo/ideas/somestuff >> t=${path_name/bozo/clown} #this will fail here... >> echo $t >> exit 0 >> >> what is the Bash alternative to do a substitution like this? > > from the Advanced Bash Scripting pdf: Substring Replacement ${string/substring/replacement} Replace first match of $substring with $replacement. ${string//substring/replacement} Replace all matches of $substring with $replacement. stringZ=abcABC123ABCabc echo ${stringZ/abc/xyz} # xyzABC123ABCabc # Replaces first match of 'abc' with 'xyz'. echo ${stringZ//abc/xyz} # xyzABC123ABCxyz # Replaces all matches of 'abc' with # 'xyz'. Your script should work. Eric
|
Pages: 1 Prev: Old version of linux? Next: Bootable USB for bootable ISO image? |