PDA

View Full Version : [SOLVED] [BASH] cat, grep.. not found?


sea
13th January 2012, 02:33 PM
Heyas

I'm currently rewriting an installation script, which, start to confuse me pretty much.

1) The script asks for whom to install (all or $(whoami)) and sets the target dir to either: /opt/sc or $HOME/sc. (working)
2) It ask if you either prefer GIT or WGET the files from SF.net (working)
3) It tries to add variables to either /etc/bashrc or $HOME/.bashrc, depending on the 'target user'.. (fail: cat, grep not found ??)
4) And finaly it calls up the script, which produces similar errors, many, actualy no commands are found :(
The git version is NOT ment to be working at this time!, however, the errors result as well with the tarball one wget.

Anyone got an idea what causes such an issue?


#!/bin/bash
# | This script is written for sc-0.1.2-all.tar.bz2, to
# be installed in a Fedora enviroment.
# | sc-0.1.2 is NOT released yet!!
# | This scripts expects to be run as $USER beeing in sudoers.
# | sudo chmod +x sc-install.sh
# ----------------------------------------------------------
# |
# | Variables
modules="lfs set sup"
# COLORS
esc="" ; whitef="${esc}[37m"; blueb="${esc}[44m"; reset="${esc}[0m"
seacolor=${whitef}${blueb}
# Tarball naming structure
tarball="sc-?.?.?-all.tar.bz2"
tmpfile=/tmp/sc-inst.swp
# USER CHOICE
defaultdir="$HOME/sc" ; defaultbash="$HOME/.bashrc"
alldir="/opt/sc" ; allbash="/etc/bashrc"
# |
# | Clean & Logo
clear
cat > /tmp/seaLogo << EOF
${seacolor}╔══════════════════════╗${reset}
${seacolor}║ ║${reset}
${seacolor}║ ╔══╗ ╔═══╗ ╔═══╗ ║${reset}
${seacolor}║ ║ ║ ║ ║ ║${reset}
${seacolor}║ ╚══╗ ╠═══╝ ╔═══╣ ║${reset}
${seacolor}║ ║ ║ ║ ║ ║${reset}
${seacolor}║ ╚══╝ ╚═══╝ ╚═══╝ ║${reset}
${seacolor}║ ║${reset}
${seacolor}╚══════════════════════╝${reset}
EOF
while read line ; do printf "\n\t\t$line" ; done < /tmp/seaLogo && printf "\n::\tLinux Scripts reloaded since 25th May 2011\t::\n"
# |
# | Destination
all="To all on this device."
echo
echo ":: Please choose for which user/s you want to install the script collection."
select target in "$all" $(whoami) ; do
if [[ "$target" = "$all" ]]
then if [[ 0 = $UID ]] ; then
targetdir=$alldir
targetbash=$allbash
else
echo "Need to reload the script with root rights."
su -c "$0 $1" && break
fi
else targetdir=$defaultdir
targetbash=$defaultdir
fi
break
done && echo
# |
# | Source
echo
aA="GIT the script files from Sourceforge.net"
bB="WGET Download latest tarball from SF.net"
echo ":: Please choose your prefered retrieve method."
select target in "$aA" "$bB" ; do
if [[ "$target" = "$aA" ]]
then git clone git://git.code.sf.net/p/seasc/core/sc-core $targetdir
for e in $modules ; do
git clone git://git.code.sf.net/p/seasc/sc-$e/sc-$e $targetdir/collection/$e
done
else mkdir -p $targetdir ; cd $targetdir
wget -nc https://sourceforge.net/projects/seasc/files/latest/download
tar -axf $tarball
fi
break
done
# |
# | Include it to current enviroment
echo
echo ":: Adding variables to $targetbash..."
scDir=$targetdir
pathadd="\$PATH:$scDir:$scDir/collection"
PATH=$pathadd
export PATH scDir
echo ":: Writing \"$scDir\" and \"$PATH\" to \"$targetbash\"..."
cat > $tmpfile << EOF
# | SC settings : start"
PATH=$pathadd"
source $scDir/sc.cfg"
export PATH scDir"
# | SC settings : end"
EOF
cat $tmpfile >> $targetbash

# |
# | Finish installation
$scDir/sc readme && echo ":: Installation successfull."


Thanks for every hint, thought or solution in advance.

glennzo
13th January 2012, 02:49 PM
As you wish Simon. Thread moved to Programming.

You are aware of sh -x scriptname.sh I hope? Sort of a debugging tool. Prints all lines to stdout. At least you can see what's happening as the script runs.

http://mywiki.wooledge.org/BashGuide/Practices#Debugging

jpollard
13th January 2012, 02:49 PM

The usual reason is a missing (or empty) PATH environment variable. When this is such, it is better to use the full path to the programs.

In some scripts you will see a configuration section at the beginning that either define aliases (such as lines like "alias cat /usr/bin/cat".

This has to purposes:
1 - ensure the program being invoked really is the one desired and not one that may get substituted (a security issue)
2 - ensures that options that may exist (such as "alias rm -i") don't cause problems with the script (a reliability and a security issue).

sea
13th January 2012, 03:26 PM
Thank you guys.
@ Glenn: Nope, wasnt aware of -x
@ Jpollard: Ah that clears it out i guess, probably mis-set PATH.

Going to try again with this in mind.

---------- Post added at 04:26 PM ---------- Previous post was at 04:20 PM ----------

It was the mis-set PATH variable.
Thank you again.

EDIT:
Hmm according to that guide i should trash my script collection strucuture, as its based on what Greg says one must not.. :blink:

glennzo
13th January 2012, 06:00 PM
Hmm according to that guide i should trash my script collection strucuture, as its based on what Greg says one must not.. :blink:
Opinions are like ****, everyone's got one. Does the code work? Good. Is it pretty? No? Who cares.