[solved] sed append into .bashrc


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [solved] sed append into .bashrc
# 1  
Old 06-01-2013
[solved] sed append into .bashrc

Hi all,

I'm trying to do a basic append into /home/joe/.bashrc:
Code:
/usr/bin/test -z `sudo /bin/grep umask /home/joe/.bashrc` && sudo /bin/sed -i '/PATH=/a \
umask 0022
' /home/joe/.bashrc

I run this as user floren with full root privileges in sudoers.
For some reason, the first command is ignored and the data is written to the file?

Edit: I solved the issue by adding the quotes to encapsulate the command:
Code:
/usr/bin/test -z "`sudo /bin/grep umask /home/joe/.bashrc`" && sudo /bin/sed -i '/PATH=/a \
umask 0022
' /home/joe/.bashrc


Last edited by TECK; 06-01-2013 at 12:09 PM..
This User Gave Thanks to TECK For This Post:
# 2  
Old 06-03-2013
Code:
file=/home/joe/.bashrc
sudo grep -q umask "$file" ||
 sudo sed -i '/PATH=/a \
umask 0022
' "$file"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Variable defined in .bashrc not intializing in script

I have the variable defined in .bashrc BIN_DIR="/usr/local/dw" and in my shell script i am using below. #!/bin/bash echo "Bin Dir: ${BIN_DIR}" . "${BIN_DIR}"/dwh_Loadfuncs.sh Output: Bin Dir: /usr/local/dw/dwh_LoadXMLFileIntoStage.sh: line 7: /dwh_Loadfuncs.sh: No such file or... (3 Replies)
Discussion started by: Ariean
3 Replies

2. Shell Programming and Scripting

[Solved] Append an header to a tab delimited file

Dear All, I would like to find an automatic way to add a given code which belong to a class at the end of the column , for example this is my input file: 0610009O20Rik V$VMYB_01 310 (+) 1 0.971 v-Myb V$EVI1_04 782 (-) 0.763 0.834 Evi-1 V$ELK1_02 1966 (-) 1 0.984 Elk-1... (4 Replies)
Discussion started by: paolo.kunder
4 Replies

3. Shell Programming and Scripting

[Solved] Find and append line to output

Hi All, I am trying to write a shell script but not getting desired output. What i am trying to do. 1.I want to use find command command and then use it xargs/exec to append the find output.But i am not getting desired output here is what i am trying to do #find init*.ora -exec `echo... (4 Replies)
Discussion started by: sahil_shine
4 Replies

4. Programming

[Solved] Append instead of overwrite

Hi, I have a script which append the .csv file which already exist but in my scenarion every time instead of appending the contect it overwrite the file and creating new .csv file. SET ORAUSR=ops$371664 SET ORAPWD=Oracle12345 SET ORADB=orcl SET DBCON=%ORAUSR%/%ORAPWD%@%ORADB% sqlplus... (1 Reply)
Discussion started by: tushar_spatil
1 Replies

5. Shell Programming and Scripting

Append file based upon user input-- solved

Ok, I have a script with a commandline option that allows the user to add a custom function to the script file. I have tried everything in my limited knowledge of sed to get this to work and keep coming up short. I need sed to search for a line starting with a pattern, I've got that part so far,... (0 Replies)
Discussion started by: DC Slick
0 Replies

6. Shell Programming and Scripting

sed append to string

I am trying to replace in multiple files every instance of text that begins with http and add hyperlink characters to it. I can get it to work with the following:sed -e "s/http*.*/<a href=\"&\">&<\/a>/g" * as long as the http text is at the end of the file. I need it to stop at the end of the... (2 Replies)
Discussion started by: numele
2 Replies

7. Shell Programming and Scripting

How to append line with sed?

Input: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly Output should be: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly How can it be done with sed? (5 Replies)
Discussion started by: cola
5 Replies

8. UNIX for Dummies Questions & Answers

[Solved] startxwin and .bashrc problem

On my old computer I always used "startxwin.bat". This worked well and when it was executed an xterm window would open and the .bashrc file in my /home/username/ folder had been read correctly and all of my aliases worked. However with the newest version of Cygwin I noticed that startxwin.bat is... (3 Replies)
Discussion started by: lemmy
3 Replies

9. Shell Programming and Scripting

How to append using sed

Hello all, I want to use sed to append a variable stored in $i, how do i do that? $i contains a path to a directory and i want to append it before the result i get from awk statement, before affecting awk results. rite now out put i get from code below is:- The path is:... (2 Replies)
Discussion started by: asirohi
2 Replies

10. UNIX for Dummies Questions & Answers

Sed: Append and Delete?

I think it should be obvious what I'm trying to do from my command, but just to be sure it's clear, I'm trying to append 2 lines after a matched line and then delete 2 other lines within a file. I'd like to do it in 1 line if possible. This code isn't working, but hopefully it's just a syntax... (0 Replies)
Discussion started by: earnstaf
0 Replies
Login or Register to Ask a Question