Unexpected sed result.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unexpected sed result.
# 1  
Old 10-14-2008
Unexpected sed result.

I am in the process of writing a script to change the grub password in the grub.conf file. I thought I had it figured out, but am running into an a problem I can't put my finger on.



Command I am running when I find that the grub.conf file contains "password --md5".
Code:
sed "s=password.*=password --md5 "$grubPW"=g" /boot/grub/grub.conf

If I run it from the shell prompt it works as expected, but when I put it into my script it doesn't replace the search string, it does add the replacement string though.

I switched the traditional '/'s to "="s because the hashed password will sometimes contain slashes.

Expected Result:
password --md5 $1$5fKefK.fw/FeMM4d2D

Actual Result:
password --md5 $1$5fKefK.fw/FeMM4d2D
password --md5

I should just end up with the one line containing the hash value.
# 2  
Old 10-15-2008
Your MD5 password contains sed and shell metacharacters, which may be interpolated in your script because $grubPW is unquoted. Quote the entire sed expression to protect the shell from interpreting the value of $grubPW. The shell will variable expand inside of double quotes:

Code:
sed "s=password.*=password --md5 $grubPW=g" /boot/grub/grub.conf

If this still has troubles, show the script segment that allows us to test the failure.
MrC
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Unexpected result from awk

Hello, Giving those commands: cat > myfile 1 2 3 ^D cat myfile | awk '{ s=s+$1 ; print s}' The output is: 1 3 6 It seems like this command iterates each time on a different row so $1 is the first field of each row.. But what caused it to refer to each row ?. What I mean... (3 Replies)
Discussion started by: uniran
3 Replies

2. Shell Programming and Scripting

sed Unexpected results, missing first search item

I created 3 files with the identical data as follows dial-peer voice 9999 pots trunkgroup CO list outgoing Local translation-profile outgoing LOCAL-7-DIGITS-NO-PREPEND-97 preference 2 shutdown destination-pattern 9......$ forward-digits 7 dial-peer voice 10000 pots ... (6 Replies)
Discussion started by: popeye
6 Replies

3. UNIX for Dummies Questions & Answers

Weird: unexpected result after piping a sort

Hello, And when you think you know the basics of something, UNIX in this case, something like what I will describe below comes along.... On a Linux system, a "typical" directory with some files. Say 20. I do: > ls | sort > mylisting Now when I: > vi mylisting There is mylisting... (13 Replies)
Discussion started by: stavros
13 Replies

4. Shell Programming and Scripting

[Solved] My sed command not give me a satisfy result

This is my command echo "Test" | sed -f <(sed -e 's/.*/s,&,gI/' mydic) In mydic file,containing 2 columns delimit by comma (,) a,AlphabetA . . . e,AlphabetE . . s,AlphabetS . t,AlphabetT test,testedd . . zebra,zebraaaa The expect result is testedd (0 Replies)
Discussion started by: Runicer
0 Replies

5. Shell Programming and Scripting

Unexpected results with lists in GNU sed

I have been living with this problem with GNU sed v4.1.4 for a long time, but now I really need to figure it out. When using a list in either an address or a search, the expression is matching lower and upper-case letters. works as it should. For example, if I run sed -nr "// p"... (7 Replies)
Discussion started by: nctrader
7 Replies

6. Shell Programming and Scripting

shell script - unexpected result

I hv a file --am executing a script which is giving me unexpected results COntents of file: f1 CMT_AP1_CONT:/opt/sybase/syboc125:150:ASE12_5::Y:UX: CMT_AP1:/opt/sybase/syboc125:150:ASE12_5::Y:UX f1.tmp CMT_AP1_CONT:/opt/sybase/syboc125:150:ASE12_5::Y:UX:... (2 Replies)
Discussion started by: rajashekar.y
2 Replies

7. Shell Programming and Scripting

Taking sed result in a variable

Hi All, How can i take the following code having three seds into a variable : echo "$DateFileFormat" | sed 's/\./\\\\./g' | sed 's/\$/+/g' | sed 's/\#/'$job_date'/g' I want to get the result stored in a script variable i tried var2=`echo "$DateFileFormat" | sed 's/\./\\\\./g' |... (4 Replies)
Discussion started by: abhinav192
4 Replies

8. Shell Programming and Scripting

How to use the result from a command in SED

Hi all, this is my first post so go gentle. My goal is to use SED to add data to the end of lines in a file, then send the results to standard output. However, I want to add the result of another command to the end of the lines. Basically: sed 's/$/ insert command stuff here/' file.txtHere... (1 Reply)
Discussion started by: jsmith_4242
1 Replies

9. Shell Programming and Scripting

unexpected pipeline result with find -exec

Hi All, I probably miss something fundamental here. I want to rename a bunch of files in subdirectories (that might contain white spaces) with names that are related. I thought following could do the job: find . -name *.sh -exec mv {} $(echo {} | sed -e 's/0/1/g') \; Now to be able to... (5 Replies)
Discussion started by: blued
5 Replies

10. Programming

unexpected 'end of file' + sed command

hello, i use this command in my code: (void) sprintf ( LBuf, "/bin/sed 's/\\//g' %s > %s", tmp1,tmp2); but i get this error : sh: syntax error at line 1:'end of file' unexpected any help please thank you (1 Reply)
Discussion started by: kamel.seg
1 Replies
Login or Register to Ask a Question