Computing.Net > Forums > Unix > converting bash script to csh script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

converting bash script to csh script

Reply to Message Icon

Name: thao
Date: August 2, 2002 at 11:45:58 Pacific
Comment:

Can anyone convert this bash script to a csh script? Essentially what this script does is it takes an a directory as an arguement and appends that to the LD_LIBRARY_PATH in the .cshrc file and sources the file.

Here's the script:
------------------
#!/bin/sh

#
# Ok, first off - make sure we were invoked with an argument. That
# argument will be the directory we want to add to LD_LIBRARY_PATH
#

if [ "$#" -ne "1" ]
then
echo "Usage: $0 dirName"
exit 1
fi

DIR="$1"

#
# Is 'DIR' a directory?
#

if [ -x $DIR ]
then
: # yep
else
echo "$DIR does not exist or is not a directory"
exit 1
fi

#
# Ok, do they have a .bashrc file?
#

BASHRC="~/.bashrc"

if [ -f $BASHRC ]
then

# yep, they do - see if there's an LD_LIBRARY_PATH entry in it
# already. Look for a line with 'LD_LIBRARY_PATH' in it
# but make sure it isn't a comment ...

RESULT=`grep -n LD_LIBRARY_PATH $BASHRC | grep -v "^[ ]*#"`

if [ "$RESULT" = "" ]
then
# no LD_LIBRARY_PATH, just tack it onto the end of their file ...

echo "export LD_LIBRARY_PATH=$DIR" >> $BASHRC
else

# Ok, grab out the line number and the current value of
# LD_LIBRARY_PATH from $RESULT

LINE_NUMBER=`echo $RESULT | awk -F: '{ print $1 }'`
VALUE=`echo $RESULT | sed 's/.*=//'`

THE_LINE="export LD_LIBRARY_PATH=$DIR:$VALUE"

if [ "$LINE_NUMBER" = "1" ]
then
echo $THE_LINE > /tmp/$$.txt
cat $BASHRC | sed -n '2,$p' >> /tmp/$$.txt
else
BEFORE=`expr $LINE_NUMBER - 1`
AFTER=`expr $LINE_NUMBER + 1`

cat $BASHRC | sed -n "1,$BEFORE"p > /tmp/$$.txt
echo $THE_LINE >> /tmp/$$.txt
cat $BASHRC | sed -n "$AFTER,$"p >> /tmp/$$.txt
fi

mv /tmp/$$.txt $BASHRC
fi

# source that sucker to life ...

. $BASHRC
fi



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


SU Command doesn't work rename all files with an ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: converting bash script to csh script

Converted BASH script acting strang www.computing.net/answers/unix/converted-bash-script-acting-strang/4385.html

running ksh to csh script in bash www.computing.net/answers/unix/running-ksh-to-csh-script-in-bash/6978.html

script to convert date/time to seco www.computing.net/answers/unix/script-to-convert-datetime-to-seco/3795.html