print -n "Enter Your password:"
stty_orig=`stty -g`
trap "stty ${stty_orig}; exit" 1 2 3 15
stty -echo >&- 2>&-
read PASS
stty ${stty_orig} >&- 2>&-
trap 1 2 3 15
print
trap :catches interruptions. I.e. if the user presses Ctrl+C, the normal stty mode is set before stopping the program
stty -echo :switches off the display echo
>&- 2>&- :helps to avoid [...]
It’s not possible to get the value of the loop variables in some versions of ksh.
Example:
#!/bin/ksh
num=0
cat $0 | while read line ; do
let num=num+1
done
echo "Number=$num"
This script will return “Number=0″ as the result on some Linux machines.
Here is the workaround for the problem: You should change the redirection method for the input file.
#!/bin/ksh
l=0
while read line ; do
let [...]
ls -1 | cpio -o | cpio -ivt | awk ‘{print $NF, $(NF-1), $(NF-4), $(NF-3) }’
Warning: I/O expensive for the large files!
Perl:
@a = localtime((stat($my_file))[9]); [...]
If the whole output of the complex script should be redirected to the log, the following trick could be used.
if [ "$1" != "-log" ] ; then
$0 -log "$@" 2>&1 | tee the_log_file.$$.log [...]
Here is very simple trick to force the grep command to display file name, when it’s used together with find operation.
Just write /dev/null as the “second file”
find . -type f -exec grep somestring {} [...]
Here is the small reminder about the syntax of the “case” command and the usage of the pattern lists.
#!/bin/ksh
print -n "Please enter the line: "
read line
case "$line" in
?(dog|cat) ) print "zero or one occurrence of any pattern" ;;
*(low|high) ) print "zero or more occurrences of any pattern" ;;
@(duncan|methos) ) print "exactly one occurrence of any pattern" [...]
echo $PATH| awk -v RS=":" ‘{ print $0 }’
echo $LD_LIBRARY_PATH |awk -v RS=":" ‘{ system ( "ls -rltd " $0 ) }’
Warning!
As far as the option ‘-v’ is used, the new awk(nawk in some systems) should be used.
To check if the new version of awk is installed:
awk 1 /dev/null
The output will be empty for new awk.
You [...]