$ ./
2.wrapper.sh 1.above_g.c
mkdir: cannot create directory ‘/home/bob/logs’: File exists
basename dollar sign zero is
2.wrapper.sh
path is /logs
Munged time is 02-07-2018_16-34-06
out fn is /home/bob/logs/02-07-2018_16-34-06.log
Time is 02-07-2018_16-34-06
Error #1: Unknown argument "1.above_g.c"
Builder v.1
---------------------------------------------------------------------------
Usage:
2.wrapper.sh filename.c
-h, --help Display this help and exit
-v, --version Output version information and exit
$ cat
2.wrapper.sh
#!/bin/bash
#
#
#
# keep a log named by time stamp
set -u
app=$(basename $0)
mkdir $HOME/logs
pathto=/logs
timename=$(date +"%m-%d-%Y_%H-%M-%S")
out=$HOME$pathto/$timename.log
echo "basename dollar sign zero is" $app
echo "path is" $pathto
echo "Munged time is" $timename
echo "out fn is $out"
echo "Time is $timename " | tee -a "$out"
TITLE='Builder'
VER='.1'
#Constants
declare -ir SUCCESS=0
declare -ir E_FATAL=1
trap_err()
{
echo " $(caller) errexit on line $1 $BASH_COMMAND exit status=$2" >&2
}
trap 'trap_err ${LINENO} $?' ERR
if [ -z ${EDITOR:-""} ] ; then
export EDITOR=$(which geany)
fi
usage()
{
cat <<EOM
$TITLE v$VER
---------------------------------------------------------------------------
Usage: $(basename $0) filename.c
-h, --help Display this help and exit
-v, --version Output version information and exit
EOM
exit $1
}
# $1 ERR_NO, $2 message
fatal_error()
{
echo -e "Error #$1: $2" >&2
echo
usage $1
}
# display script version
version()
{
echo "$app v$VER"
exit $SUCCESS
}
#User confirmation
confirm()
{
MSG="Do you want to do something?"
zenity --question --text="$MSG" --title="$TITLE" --display=:0 ||
exit $SUCCESS
}
#User notification
notify()
{
MSG="processing complete"
notify-send "$TITLE" "$MSG" || exit $SUCCESS
}
# Parse command line for options
if (( $# ))
then
case $1 in
-h | --help | -\?) usage $SUCCESS;;
-v | --version) version;;
*) fatal_error $E_FATAL "Unknown argument \"$1\"";;
esac
else
confirm
fi
##### begin wrappee
# source file name comes in on $1
cd /home/bob/projects/1.scripts
pwd | tee -a "$out"
cat $1 | tee -a "$out"
gcc -Wall -o natasha $1 | tee -a "$out"
natasha | tee -a "$out"
##### resume wrapper
$EDITOR $1 &
cat $app | tee -a "$out"
echo "duration=$SECONDS" | tee -a "$out"
gedit $out &
exit $SUCCESS
$
The above is a C wrapper script, where the c-part isn't much different
than "hello world." The bash part is something I abducted from jonathan
tuttle a while back to become my nominal driver. It has been nicked, sat
on by a cat, dropped on its head, but also not comprehended in parts,
and these are the parts I would like to visit now, as this extension
gives opportunity. Given partial ignorance of the syntax I'm using, the
flaws are mine, whatever the provenance.
if (( $# ))
then
case $1 in
-h | --help | -\?) usage $SUCCESS;;
-v | --version) version;;
*) fatal_error $E_FATAL "Unknown argument \"$1\"";;
esac
else
confirm
fi
How do I re-write this part so that I can achieve the usage, and have $1
interpolate into my gcc commands thereafter?
Thanks for your comment,
--
fred flintstone