I need to pass defaults to the -c -t -u flags. in the -c i need that to be infinite in the -t i need that to be 1 sec and in the -u the defauls is ANY user
#!/bin/bash
set -u
print_usage(){
echo "usage: script[-c] [-t] [-u] exe-name"
}
if [[ $# -eq 0 ]]; then
print_usage
exit 1
fi
while getopts :c:t:u: flag; do
case $flag in
c) counts=$OPTARG;;
t) timeout=$OPTARG;;
u) user_name=$OPTARG;;
esac
done
if [ $counts==true ]
then
top -n ${counts}
fi
if [ $timeout==true ]
then
top -d ${timeout}
fi
if [ $user_name==true ]
then
top -u ${user_name}
fi
I tried to put something like that in the biginning but it doesn't work:
counts=
timeout=1
user_name=.