Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 08-26-2010, 07:34 PM   #1
LQ Newbie
Registered: Aug 2007
Posts: 6

Rep: Reputation: 0
Redirect output of a command to another file inside shell script


I am writing a script in which I am using AWK to append to a line in a file and save the file. The command I am using is:
awk '{s=$0; if ( NR==4 ){s=s ":/usr/java/jdk1.6.0_19/bin" } print s;}' $appName > $
This works perfectly on the command line. However when I insert the same command in my shell script, the script ignores everything after the first $appName.

The $appName variable is an input to the script.

Similar thing happens when I use SED to replace a piece of text in another file in the same script.

sed 's/DEV/UAT/g' Properties>Properties.tmp
Again, this works perfectly on command line.

My shell is BASH & I am using Redhat Enterprise Linux.

My entire script is:
export APPPATH=~/Library/WebObjects/Applications
export APPNAME=$1

# Prepare the deployment env.
    typeset appName=$1
    cd ~/Builds
    if [[ -e $appName* ]]; then        rm $appName*
    curl -O'$'$appName/lastSuccessfulBuild/artifact/$appName/$appName-

    tar -C ~/Backups/ -xf $appName*

    # Modify the path declaration line in the Application launch file.
    typeset appName=$1
    typeset appPath=$APPPATH
    cd $appPath/$appName.woa
    exec awk '{s=$0; if ( NR==4 ){s=s ":/usr/java/jdk1.6.0_19/bin" } print s;}' $appName > $
# | mv $appName.tmp $appName | chmod +x $appName

    #Modify the Environment Setting in the Properties file from DEV to UAT
    typeset appName=$1
    typeset appPath=$APPPATH/$appName.woa/Contents/Resources
    cd $appPath
    exec sed 's/DEV/UAT/g' Properties>Properties.tmp &&  mv Properties.tmp Properties

prep_env $APPNAME
append_path $APPNAME
modify_prop $APPNAME
Old 08-26-2010, 10:16 PM   #2
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
- How do you call your script?
- No need to use 'exec'
- You can use 'sed -i' to edit inline
Old 08-27-2010, 03:36 AM   #3
LQ Newbie
Registered: Aug 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Not using exec

I am actually not using exec. I found suggestions on some other threads on this forum about using exec. But it does not help.

I am not very well conversant with the sed command. I am just using basic features. I will check it out tomorrow.
Old 08-27-2010, 04:28 AM   #4
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 403Reputation: 403Reputation: 403Reputation: 403Reputation: 403
awk '{s=$0; if ( NR==4 ){s=s ":/usr/java/jdk1.6.0_19/bin" } print s;}' $appName > $
I suggest you to check the value of "$appName" before running awk. For a quick check, 'echo "$appName"' will work.
Old 08-27-2010, 03:23 PM   #5
LQ Newbie
Registered: Aug 2007
Posts: 6

Original Poster
Rep: Reputation: 0
$appName resolves correctly.

I suggest you to check the value of "$appName" before running awk. For a quick check, 'echo "$appName"' will work.
The same command works perfectly on command prompt. The $appName variable is the same used earlier in the script and it resolves correctly.

Also when I run the script in debug mode using -x, it shows $appName resolving to correct parameter. However, it does not show anything after the $appName i.e. the > $

Why is this happening?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to redirect the SCP command output to text file. gokuls Linux - General 10 02-22-2012 03:12 AM
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 01:21 PM
invoking windows command inside a shell script nano2 Programming 6 09-09-2009 04:46 AM
Unable to redirect script output to a file alien12 Linux - Newbie 4 08-25-2009 04:36 AM
Shell scripting: How to redirect output from within the script itself? Arodef Linux - General 4 05-23-2006 08:30 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:28 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration