Bash script to check command-line arguments and set default if not present?
if [ -n "$1" ]
# Test whether command-line argument is present (non-empty).
then
lines=$1
else
lines=$LINES # Default, if not specified on command-line.
fi
Script to check weather user is root or not?
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
Bash Script to find CPU type or model?
#!/bin/sh
if [ -f /proc/cpuinfo ]; then
echo -n "MODELNAME=\""
grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | sed -e 's/^ *//' | sed -e 's/$/"/'
fi
OUTPUT:
MODELNAME="Intel(R) Core(TM)2 Duo CPU E8200 @ 2.66GHz"
Bash Script to find system architecture?
#!/bin/sh
echo ARCH=`uname -m`
OUTPUT:
ARCH=x86_64
if [ -n "$1" ]
# Test whether command-line argument is present (non-empty).
then
lines=$1
else
lines=$LINES # Default, if not specified on command-line.
fi
Script to check weather user is root or not?
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
Bash Script to find CPU type or model?
#!/bin/sh
if [ -f /proc/cpuinfo ]; then
echo -n "MODELNAME=\""
grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | sed -e 's/^ *//' | sed -e 's/$/"/'
fi
OUTPUT:
MODELNAME="Intel(R) Core(TM)2 Duo CPU E8200 @ 2.66GHz"
Bash Script to find system architecture?
#!/bin/sh
echo ARCH=`uname -m`
OUTPUT:
ARCH=x86_64