Sponsored Content
Top Forums Shell Programming and Scripting Add Variable in .bash_profile Post 302524578 by mirni on Tuesday 24th of May 2011 01:28:33 AM
Old 05-24-2011
This sed command inserts (i) a line 'IMPACT_HOME=/my/new/path' before every line in infile; which is almost certainly not what you want.
You may want to make #1 look like:
Code:
grep -q IMPACT_HOME infile || sed '$ a IMPACT_HOME=/my/new/path' infile

which will append (a) the line at the end of file ($).

#2 is a little trickier. I think the intention was to substitute the definition of IMAPCT_HOME with a new path, however, this is a not quite well designed solution. The sed command there will replace any occurence of IMPACT_HOME until the end of line with 'IMPACT_HOME=/my/new/path'.
But what if infile contains some other statements containing IMPACT HOME, that are not a definition of it? E.g.:
Code:
if [ -z "$IMPACT_HOME" ] ; then 
 #do something
fi

would change into
Code:
if [ -z "$IMPACT_HOME=/my/new/path
 #do something
fi

and create syntax error(s).
I'd write #2 like this:
Code:
grep -q IMPACT_HOME infile && sed -i 's!^\([^#]*IMPACT_HOME=\)\(.*\)!\1/my/new/path #\2!' infile

Which will change the first line containing 'IMPACT_HOME='.
It will put the old definition (string after equal sign) into a comment on the same line. So, e.g. line:
Code:
IMPACT_HOME=/old/path

will become
Code:
IMPACT_HOME=/my/new/path #/old/path

It will only change (at most) one line (no 'g' at the end); and it will not change lines containing pound symbol before IMPACT_HOME (comments).

#1 and #2 can actually be put together into one (albeit long) line:
Code:
grep -q IMPACT_HOME infile && sed -i 's!^\([^#]*IMPACT_HOME=\)\(.*\)!\1/my/new/path #\2!' infile || sed '$ a IMPACT_HOME=/my/new/path' infile

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unrecognized Path in .bash_profile

Dear experts, I have installed Ruby in the following directory: $ pwd /home/ewijaya/.ruby $ ls bin lib share And I have also stated the PATH in my bash_profile like this: # .bash_profile # Get the aliases and functions if ; then . ~/.bashrc (1 Reply)
Discussion started by: monkfan
1 Replies

2. Shell Programming and Scripting

.bash_profile problem

Hi Guys, I modified my .bash_profile script , and tried to change the prompt. Following is the line of code in my .bash_profile script. export PS1=" \W " But I get the output as: \W This appears to be my prompt now. Any idea what should be done.. Thanks! (0 Replies)
Discussion started by: nua7
0 Replies

3. Shell Programming and Scripting

question in .bash_profile

We are more users using the oracle account, and people want to include theyr own files in .bash_profile. Like this: while ; do echo -n "LOGNAME is '$LOGNAME' (no sens), who are you? " >/dev/stderr read ln export LOGNAME=$ln done This works well when logging in to... (1 Reply)
Discussion started by: hannem
1 Replies

4. UNIX for Dummies Questions & Answers

bash_profile does not working

Hi all. when i connect as user megaguru i have a problem my .bash_profile does not working^:( if i do: . ./.bash_profile all enviroment variables are in place. How can i force linux to use .bash_profile before logon process? thanx in advance. (1 Reply)
Discussion started by: smallman
1 Replies

5. UNIX for Advanced & Expert Users

bash_profile or .profile

Hi, happy new year. on AIX 6.1 , for user oracle , there are two files : bash_profile and .profile I do not know which one is executed when login ? How to know , More over in both of them we have : in .profile : ORACLE_HOME=/appli/oracle/product/10.2.0/db_1... (5 Replies)
Discussion started by: big123456
5 Replies

6. Linux

How to add entry into .bash_profile file

Hi, Currently If i have created new userID then .bash_profile file is created under the new user. Now, I would like to add one path in this file. Please help on this . Current file output: # .bash_profile # Get the aliases and functions if ; then . ~/.bashrc fi #... (4 Replies)
Discussion started by: Mani_apr08
4 Replies

7. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

8. Red Hat

.bash_profile file corrupted

Hi, Unexpectedly i entered wrong entries in .bash_profile for my user which has administrative permissions. So, i am getting errors for every command. I dont have backup file also, so any body can help me how to recover it. Regards, Mastan (7 Replies)
Discussion started by: mastansaheb
7 Replies

9. Shell Programming and Scripting

Is there a way to organize bash_profile across different platforms

I want to have one .bash_profile works on multiple platform, ubuntu, debian, redhat, cygwin, osx. So how should I organize .bash_profile? It can be multiple files in some subdir Let me brief you: what i want is a way to organize bash_profile across platforms so I can use one set of profiles... (2 Replies)
Discussion started by: John_Peter
2 Replies

10. UNIX for Dummies Questions & Answers

.bash_profile question

Hello everyone, I'm trying to set my .bash_profile to change my primary prompt from this: banbatchtest1v:MCPPRD:~>to this: banbatchtest1v:MCPPRD:/home/rcarvall> Here's what my .bash_profile looks like right now: # .bash_profile # Get the aliases and functions if ; then .... (2 Replies)
Discussion started by: galileo1
2 Replies
MEWENCODE(1)                                                  General Commands Manual                                                 MEWENCODE(1)

NAME
mewencode, mewdecode, mewcat - MIME encoder/decoder SYNOPSIS
mewencode [-options] [infile [outfile]] mewdecode [-options] [infile [outfile]] mewcat [-options] [infile] DESCRIPTION
The mewencode utility encode/decode MIME objects. The options are as follows: -e Encoding. -d Decoding. -8 See if any 8bit characters are contained. -b MIME base64 en/decoding. -q MIME quoted-printable en/decoding. -g MIME gzip64 en/decoding(not yet specified in RFC). -z The same as -g. -u Uudecoding. -l length Line length into which base64/quoted-printable/gzip64 encoding truncate. -t On base64/gzip64 encoding, local newline is treated as CRLF. On base/gzip64 decoding, any newline is translated into local new- line. Specify this option only when the input is a line based object(e.g. Content-Type: is text/plain or application/postscript). -h Display this help message. -v Display the version. 4th Berkeley Distribution March 17, 2001 MEWENCODE(1)
All times are GMT -4. The time now is 09:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy