head 1.44; access; symbols SHTOOL_2_0_8:1.44 SHTOOL_2_0_7:1.43 SHTOOL_2_0_6:1.40 SHTOOL_2_0_5:1.40 SHTOOL_2_0_4:1.40 SHTOOL_2_0_3:1.39 SHTOOL_2_0_2:1.39 SHTOOL_2_0_1:1.38 SHTOOL_2_0_0:1.38 SHTOOL_2_0b3:1.38 SHTOOL_2_0b2:1.38 SHTOOL_2_0b1:1.38 SHTOOL_1_6:1.32.0.2 SHTOOL_1_6_2:1.32 SHTOOL_1_6_1:1.30 SHTOOL_1_6_0:1.29 SHTOOL_1_5:1.27.0.2 SHTOOL_1_5_4:1.27 SHTOOL_1_5_3:1.24 SHTOOL_1_5_2:1.24 SHTOOL_1_5_1:1.23 SHTOOL_1_5_0:1.23 SHTOOL_1_4_9:1.23 SHTOOL_1_4_8:1.22 SHTOOL_1_4_7:1.20 SHTOOL_1_4_6:1.19 SHTOOL_1_4_5:1.19 SHTOOL_1_4_4:1.19 SHTOOL_1_4_3:1.19 SHTOOL_1_4_2:1.19 SHTOOL_1_4_1:1.19 SHTOOL_1_4_0:1.19 SHTOOL_1_3_3:1.16 SHTOOL_1_3_2:1.15 SHTOOL_1_3_1:1.14 SHTOOL_1_3_0:1.14 SHTOOL_1_2_9:1.4 SHTOOL_1_2_8:1.3 SHTOOL_1_2_7:1.1.1.1 SHTOOL_1_2_6:1.1.1.1 SHTOOL_1_2_5:1.1.1.1 SHTOOL_1_2_4:1.1.1.1 SHTOOL_1_2_3:1.1.1.1 SHTOOL_1_2_2:1.1.1.1 SHTOOL_1_2_1:1.1.1.1 SHTOOL_1_2_0:1.1.1.1 SHTOOL_1_1_0:1.1.1.1 RSE:1.1.1; locks; strict; comment @# @; 1.44 date 2008.04.02.20.13.43; author rse; state Exp; branches; next 1.43; commitid eB5Wirx8MdMyDzXs; 1.43 date 2007.05.19.19.09.39; author rse; state Exp; branches; next 1.42; commitid OPUF1UBbllBTwzis; 1.42 date 2006.09.29.06.36.31; author rse; state Exp; branches; next 1.41; commitid MCDHq8ODwC8jPGOr; 1.41 date 2006.09.29.06.13.17; author rse; state Exp; branches; next 1.40; commitid NkUORetFQxijHGOr; 1.40 date 2006.02.04.09.43.25; author rse; state Exp; branches; next 1.39; commitid oWk7BmnyAitJtfkr; 1.39 date 2005.06.15.08.14.35; author rse; state Exp; branches; next 1.38; 1.38 date 2004.02.12.16.06.26; author rse; state Exp; branches; next 1.37; 1.37 date 2004.01.01.16.54.20; author rse; state Exp; branches; next 1.36; 1.36 date 2003.08.13.14.20.34; author rse; state Exp; branches; next 1.35; 1.35 date 2003.02.22.12.27.20; author rse; state Exp; branches; next 1.34; 1.34 date 2003.02.21.19.18.34; author rse; state Exp; branches; next 1.33; 1.33 date 2003.02.11.13.00.50; author rse; state Exp; branches; next 1.32; 1.32 date 2002.10.30.16.21.51; author rse; state Exp; branches; next 1.31; 1.31 date 2002.10.07.05.02.12; author rse; state Exp; branches; next 1.30; 1.30 date 2002.02.23.09.18.03; author rse; state Exp; branches; next 1.29; 1.29 date 2001.12.31.15.06.04; author rse; state Exp; branches; next 1.28; 1.28 date 2001.09.23.10.58.10; author rse; state Exp; branches; next 1.27; 1.27 date 2001.06.14.14.24.16; author rse; state Exp; branches; next 1.26; 1.26 date 2001.06.13.21.30.05; author rse; state Exp; branches; next 1.25; 1.25 date 2001.06.13.08.54.50; author rse; state Exp; branches; next 1.24; 1.24 date 2001.01.17.09.55.11; author rse; state Exp; branches; next 1.23; 1.23 date 2000.03.24.15.22.51; author rse; state Exp; branches; next 1.22; 1.22 date 2000.03.12.13.28.24; author rse; state Exp; branches; next 1.21; 1.21 date 2000.03.12.11.12.21; author rse; state Exp; branches; next 1.20; 1.20 date 99.10.06.11.59.11; author rse; state Exp; branches; next 1.19; 1.19 date 99.07.02.07.46.29; author rse; state Exp; branches; next 1.18; 1.18 date 99.07.02.06.09.30; author rse; state Exp; branches; next 1.17; 1.17 date 99.07.01.15.02.47; author rse; state Exp; branches; next 1.16; 1.16 date 99.06.29.17.37.34; author rse; state Exp; branches; next 1.15; 1.15 date 99.06.28.15.18.44; author rse; state Exp; branches; next 1.14; 1.14 date 99.06.25.14.20.04; author rse; state Exp; branches; next 1.13; 1.13 date 99.06.24.14.10.58; author rse; state Exp; branches; next 1.12; 1.12 date 99.06.24.10.12.21; author rse; state Exp; branches; next 1.11; 1.11 date 99.06.23.07.12.04; author rse; state Exp; branches; next 1.10; 1.10 date 99.06.17.15.25.32; author rse; state Exp; branches; next 1.9; 1.9 date 99.06.17.15.09.55; author rse; state Exp; branches; next 1.8; 1.8 date 99.06.12.14.46.37; author rse; state Exp; branches; next 1.7; 1.7 date 99.06.12.14.08.49; author rse; state Exp; branches; next 1.6; 1.6 date 99.06.09.18.23.34; author rse; state Exp; branches; next 1.5; 1.5 date 99.06.04.07.17.45; author rse; state Exp; branches; next 1.4; 1.4 date 99.06.01.10.02.23; author rse; state Exp; branches; next 1.3; 1.3 date 99.05.28.06.57.44; author rse; state Exp; branches; next 1.2; 1.2 date 99.05.25.15.46.58; author rse; state Exp; branches; next 1.1; 1.1 date 99.04.29.11.19.49; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.04.29.11.19.49; author rse; state Exp; branches; next ; desc @@ 1.44 log @adjust copyright for year 2008 @ text @## ## echo -- Print string with optional construct expansion ## Copyright (c) 1998-2008 Ralf S. Engelschall ## ## This file is part of shtool and free software; you can redistribute ## it and/or modify it under the terms of the GNU General Public ## License as published by the Free Software Foundation; either version ## 2 of the License, or (at your option) any later version. ## ## This file is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, ## USA, or contact Ralf S. Engelschall . ## str_tool="echo" str_usage="[-n|--newline] [-e|--expand] [ ...]" arg_spec="0+" opt_spec="n.e." opt_alias="n:newline,e:expand" opt_n=no opt_e=no . ./sh.common text="$*" # check for broken escape sequence expansion seo='' bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'` if [ ".$bytes" != .3 ]; then bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'` if [ ".$bytes" = .3 ]; then seo='-E' fi fi # check for existing -n option (to suppress newline) minusn='' bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'` if [ ".$bytes" = .3 ]; then minusn='-n' fi # determine terminal bold sequence term_bold='' term_norm='' if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[Bb]'`" != . ]; then case $TERM in # for the most important terminal types we directly know the sequences xterm|xterm*|vt220|vt220*) term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' /dev/null` term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' /dev/null` ;; vt100|vt100*|cygwin) term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' /dev/null` term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' /dev/null` ;; # for all others, we try to use a possibly existing `tput' or `tcout' utility * ) paths=`echo $PATH | sed -e 's/:/ /g'` for tool in tput tcout; do for dir in $paths; do if [ -r "$dir/$tool" ]; then for seq in bold md smso; do # 'smso' is last bold="`$dir/$tool $seq 2>/dev/null`" if [ ".$bold" != . ]; then term_bold="$bold" break fi done if [ ".$term_bold" != . ]; then for seq in sgr0 me rmso init reset; do # 'reset' is last norm="`$dir/$tool $seq 2>/dev/null`" if [ ".$norm" != . ]; then term_norm="$norm" break fi done fi break fi done if [ ".$term_bold" != . ] && [ ".$term_norm" != . ]; then break; fi done ;; esac if [ ".$term_bold" = . ] || [ ".$term_norm" = . ]; then echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2 term_bold='' term_norm='' fi fi # determine user name username='' if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[uUgG]'`" != . ]; then username="`(id -un) 2>/dev/null`" if [ ".$username" = . ]; then str="`(id) 2>/dev/null`" if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then username=`echo $str | sed -e 's/^uid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'` fi if [ ".$username" = . ]; then username="$LOGNAME" if [ ".$username" = . ]; then username="$USER" if [ ".$username" = . ]; then username="`(whoami) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" if [ ".$username" = . ]; then username="`(who am i) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" if [ ".$username" = . ]; then username='unknown' fi fi fi fi fi fi fi # determine user id userid='' if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%U'`" != . ]; then userid="`(id -u) 2>/dev/null`" if [ ".$userid" = . ]; then userid="`(id -u ${username}) 2>/dev/null`" if [ ".$userid" = . ]; then str="`(id) 2>/dev/null`" if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*$//'` fi if [ ".$userid" = . ]; then userid=`(getent passwd ${username}) 2>/dev/null | \ sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$userid" = . ]; then userid=`grep "^${username}:" /etc/passwd 2>/dev/null | \ sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$userid" = . ]; then userid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \ sed -e 'q' | sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$userid" = . ]; then userid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \ sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$userid" = . ]; then userid='?' fi fi fi fi fi fi fi fi # determine (primary) group id groupid='' if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[gG]'`" != . ]; then groupid="`(id -g ${username}) 2>/dev/null`" if [ ".$groupid" = . ]; then str="`(id) 2>/dev/null`" if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then groupid=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*//' -e 's/(.*$//'` fi if [ ".$groupid" = . ]; then groupid=`(getent passwd ${username}) 2>/dev/null | \ sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$groupid" = . ]; then groupid=`grep "^${username}:" /etc/passwd 2>/dev/null | \ sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$groupid" = . ]; then groupid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \ sed -e 'q' | sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$groupid" = . ]; then groupid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \ sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` if [ ".$groupid" = . ]; then groupid='?' fi fi fi fi fi fi fi # determine (primary) group name groupname='' if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%g'`" != . ]; then groupname="`(id -gn ${username}) 2>/dev/null`" if [ ".$groupname" = . ]; then str="`(id) 2>/dev/null`" if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then groupname=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'` fi if [ ".$groupname" = . ]; then groupname=`(getent group) 2>/dev/null | \ grep "^[^:]*:[^:]*:${groupid}:" | \ sed -e 's/:.*$//'` if [ ".$groupname" = . ]; then groupname=`grep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \ sed -e 's/:.*$//'` if [ ".$groupname" = . ]; then groupname=`(ypcat group; niscat group) 2>/dev/null | \ sed -e 'q' | grep "^[^:]*:[^:]*:${groupid}:" | \ sed -e 's/:.*$//'` if [ ".$groupname" = . ]; then groupname=`(nidump group .) 2>/dev/null | \ grep "^[^:]*:[^:]*:${groupid}:" | \ sed -e 's/:.*$//'` if [ ".$groupname" = . ]; then groupname='?' fi fi fi fi fi fi fi # determine host and domain name hostname='' domainname='' if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%h'`" != . ]; then hostname="`(uname -n) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" if [ ".$hostname" = . ]; then hostname="`(hostname) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" if [ ".$hostname" = . ]; then hostname='unknown' fi fi case $hostname in *.* ) domainname=".`echo $hostname | cut -d. -f2-`" hostname="`echo $hostname | cut -d. -f1`" ;; esac fi if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%d'`" != . ]; then if [ ".$domainname" = . ]; then if [ -f /etc/resolv.conf ]; then domainname="`grep '^[ ]*domain' /etc/resolv.conf | sed -e 'q' |\ sed -e 's/.*domain//' \ -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \ -e 's/^\.//' -e 's/^/./' |\ awk '{ printf("%s", $1); }'`" if [ ".$domainname" = . ]; then domainname="`grep '^[ ]*search' /etc/resolv.conf | sed -e 'q' |\ sed -e 's/.*search//' \ -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \ -e 's/ .*//' -e 's/ .*//' \ -e 's/^\.//' -e 's/^/./' |\ awk '{ printf("%s", $1); }'`" fi fi fi fi # determine current time time_day='' time_month='' time_year='' time_monthname='' if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[DMYm]'`" != . ]; then time_day=`date '+%d'` time_month=`date '+%m'` time_year=`date '+%Y' 2>/dev/null` if [ ".$time_year" = . ]; then time_year=`date '+%y'` case $time_year in [5-9][0-9]) time_year="19$time_year" ;; [0-4][0-9]) time_year="20$time_year" ;; esac fi case $time_month in 1|01) time_monthname='Jan' ;; 2|02) time_monthname='Feb' ;; 3|03) time_monthname='Mar' ;; 4|04) time_monthname='Apr' ;; 5|05) time_monthname='May' ;; 6|06) time_monthname='Jun' ;; 7|07) time_monthname='Jul' ;; 8|08) time_monthname='Aug' ;; 9|09) time_monthname='Sep' ;; 10) time_monthname='Oct' ;; 11) time_monthname='Nov' ;; 12) time_monthname='Dec' ;; esac fi # expand special ``%x'' constructs if [ ".$opt_e" = .yes ]; then text=`echo $seo "$text" |\ sed -e "s/%B/${term_bold}/g" \ -e "s/%b/${term_norm}/g" \ -e "s/%u/${username}/g" \ -e "s/%U/${userid}/g" \ -e "s/%g/${groupname}/g" \ -e "s/%G/${groupid}/g" \ -e "s/%h/${hostname}/g" \ -e "s/%d/${domainname}/g" \ -e "s/%D/${time_day}/g" \ -e "s/%M/${time_month}/g" \ -e "s/%Y/${time_year}/g" \ -e "s/%m/${time_monthname}/g" 2>/dev/null` fi # create output if [ .$opt_n = .no ]; then echo $seo "$text" else # the harder part: echo -n is best, because # awk may complain about some \xx sequences. if [ ".$minusn" != . ]; then echo $seo $minusn "$text" else echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text" fi fi shtool_exit 0 ## ## manual page ## =pod =head1 NAME B - B echo(1) extensional command =head1 SYNOPSIS B [B<-n>|B<--newline>] [B<-e>|B<--expand>] I =head1 DESCRIPTION B is an echo(1) style command which prints I to F and optionally provides special expansion constructs (terminal bold mode, environment details, date, etc) and newline control. The trick of this command is that it provides a portable B<-n> option and hides the gory details needed to find out the environment details under option B<-e>. =head1 OPTIONS The following command line options are available. =over 4 =item B<-n>, B<--newline> By default, output is written to F followed by a "newline" (ASCII character 0x0a). If option B<-n> is used, this newline character is omitted. =item B<-e>, B<--expand> If option B<-e> is used, I can contain special "B<%>I" constructs which are expanded before the output is written. Currently the following constructs are recognized: =over 4 =item B<%B> switch terminal mode to bold display mode. =item B<%b> switch terminal mode back to normal display mode. =item B<%u> the current user name. =item B<%U> the current user id (numerical). =item B<%g> the current group name. =item B<%G> the current group id (numerical). =item B<%h> the current hostname (without any domain extension). =item B<%d> the current domain name. =item B<%D> the current day of the month. =item B<%M> the current month (numerical). =item B<%m> the current month name. =item B<%Y> the current year. =back =back =head1 EXAMPLE # shell script shtool echo -n -e "Enter your name [%B%u%b]: "; read name shtool echo -e "Your Email address might be %u@@%h%d" shtool echo -e "The current date is %D-%m-%Y" =head1 HISTORY The B B command was originally written by Ralf S. Engelschall Erse@@engelschall.comE in 1998 for I (WML) under the name B. It was later taken over into B. =head1 SEE ALSO shtool(1), echo(1). =cut @ 1.43 log @Adjust copyright for year 2007. @ text @d3 1 a3 1 ## Copyright (c) 1998-2007 Ralf S. Engelschall @ 1.42 log @add NIS+ support, too @ text @d3 1 a3 1 ## Copyright (c) 1998-2006 Ralf S. Engelschall @ 1.41 log @Fix and enhance "shtool echo -e" command by adding a missing line-continuation and adding support for MacOS X via nidump(8). @ text @d149 2 a150 2 userid=`(ypmatch "${username}" passwd) 2>/dev/null | \ sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` d181 2 a182 2 groupid=`(ypmatch "${username}" passwd) 2>/dev/null | \ sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` d213 2 a214 2 groupname=`(ypcat group) 2>/dev/null | \ grep "^[^:]*:[^:]*:${groupid}:" | \ @ 1.40 log @Adjust copyright for year 2006 @ text @d149 1 a149 2 userid=`(ypcat passwd) 2>/dev/null | grep "^${username}:" | \ d152 5 a156 1 userid='?' d181 1 a181 1 groupid=`(ypcat passwd) 2>/dev/null | grep "^${username}:" | \ d184 5 a188 1 groupid='?' d217 6 a222 1 groupname='?' @ 1.39 log @Adjust copyright for year 2005 @ text @d3 1 a3 1 ## Copyright (c) 1998-2005 Ralf S. Engelschall @ 1.38 log @Embedded the command documentation from shtool.pod into the individual sh.xxxx scripts and this way split the large shtool(1) manual page into individual manual pages shtool-xxxx(1). Submitted partly by: Thomas Lotterer @ text @d3 1 a3 1 ## Copyright (c) 1998-2004 Ralf S. Engelschall @ 1.37 log @Bump copyright year for 2004 @ text @a3 1 ## Originally written for WML as buildinfo d22 1 a22 1 str_usage="[-n|--newline] [-e|--expand] [ ...]" d319 120 @ 1.36 log @Replace "[ x -o/-a x ]" constructs with "[ x ] ||/&& [ x ]" and "egrep"/"fgrep" constructs with compatible "grep" or "case" constructs. This way GNU shtool is now more POSIX 1003.1-2001 compliant. Submitted by: Paul Eggert @ text @d3 1 a3 1 ## Copyright (c) 1998-2003 Ralf S. Engelschall @ 1.35 log @Enhance %u, %U, %g and %G expansions of "shtool echo -e" by also trying the Solaris/Linux "getent" command. Hint by: Christoph Schug @ text @d54 1 a54 1 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[Bb]'`" != . ]; then d90 1 a90 1 if [ ".$term_bold" != . -a ".$term_norm" != . ]; then d96 1 a96 1 if [ ".$term_bold" = . -o ".$term_norm" = . ]; then d105 1 a105 1 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[uUgG]'`" != . ]; then d134 1 a134 1 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%U'`" != . ]; then d147 1 a147 1 userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \ d151 1 a151 1 egrep "^${username}:" | \ d165 1 a165 1 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[gG]'`" != . ]; then d176 1 a176 1 groupid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \ d179 1 a179 1 groupid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \ d192 1 a192 1 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%g'`" != . ]; then d201 1 a201 1 egrep "^[^:]*:[^:]*:${groupid}:" | \ d204 1 a204 1 groupname=`egrep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \ d208 1 a208 1 egrep "^[^:]*:[^:]*:${groupid}:" | \ d222 1 a222 1 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%h'`" != . ]; then d239 1 a239 1 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%d'`" != . ]; then d242 1 a242 1 domainname="`egrep '^[ ]*domain' /etc/resolv.conf | sed -e 'q' |\ d248 1 a248 1 domainname="`egrep '^[ ]*search' /etc/resolv.conf | sed -e 'q' |\ d264 1 a264 1 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[DMYm]'`" != . ]; then @ 1.34 log @Enhance %u, %U, %g and %G expansions of "shtool echo -e" by first trying to resolve via POSIX "id" command. Parts submitted by: Bill Campbell @ text @d144 1 a144 1 userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \ d147 1 a147 2 userid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \ d150 6 a155 1 userid='?' d173 1 a173 1 groupid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \ d176 1 a176 1 groupid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \ d179 5 a183 1 groupid='?' d200 2 a201 1 groupname=`egrep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \ d204 1 a204 2 groupname=`(ypcat group) 2>/dev/null | \ egrep "^[^:]*:[^:]*:${groupid}:" | \ d207 6 a212 1 groupname='?' @ 1.33 log @Bump year in copyright messages to cover new year 2003. @ text @d106 1 a106 1 username="$LOGNAME" d108 4 a111 1 username="$USER" d113 1 a113 2 username="`(whoami) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" d115 1 a115 2 username="`(who am i) 2>/dev/null |\ awk '{ printf("%s", $1); }'`" d117 9 a125 1 username='unknown' d137 1 a137 4 str="`(id) 2>/dev/null`" if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*//'` fi d139 4 a142 2 userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \ sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` d144 1 a144 2 userid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \ d147 6 a152 1 userid='?' d162 1 a162 2 groupid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \ sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` d164 4 a167 2 groupid=`(ypcat passwd) 2>/dev/null | egrep "^${username}:" | \ sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'` d169 9 a177 1 groupid='?' d185 1 a185 2 groupname=`egrep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \ sed -e 's/:.*$//'` d187 4 a190 3 groupname=`(ypcat group) 2>/dev/null | \ egrep "^[^:]*:[^:]*:${groupid}:" | \ sed -e 's/:.*$//'` d192 10 a201 1 groupname='?' @ 1.32 log @Support bold font on 'cygwin' terminals. Submitted by: Marcus Boerger @ text @d3 1 a3 1 ## Copyright (c) 1998-2002 Ralf S. Engelschall @ 1.31 log @Try the terminal 'init' sequence before 'reset' for bold mode restoring in order to make sure the terminal is not cleared. Additionally, fallback to a consistent no-bold mode. Submitted by: Mirko Liss @ text @d61 1 a61 1 vt100|vt100*) @ 1.30 log @Port to POSIX 1003.1-2001 (SUSv3) standard: sh.echo, sh.version: "head -1" -> "sed -e 'q'" sh.path: "sort -u | tail -1" -> "sort -r -u | sed -e q" sh.subst: diff -u1 -> diff -U1 Submitted by: Paul Eggert @ text @d79 1 a79 1 for seq in sgr0 me rmso reset; do # 'reset' is last d98 2 @ 1.29 log @bump copyright years @ text @d197 1 a197 1 domainname="`egrep '^[ ]*domain' /etc/resolv.conf | head -1 |\ d203 1 a203 1 domainname="`egrep '^[ ]*search' /etc/resolv.conf | head -1 |\ @ 1.28 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1998-2001 Ralf S. Engelschall @ 1.27 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="[-n] [-e] [ ...]" d26 1 @ 1.26 log @*** empty log message *** @ text @d51 1 a51 1 term_bold='' @ 1.25 log @*** empty log message *** @ text @d102 1 a102 1 if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[uU]'`" != . ]; then d144 29 d252 2 @ 1.24 log @*** empty log message *** @ text @d144 1 a144 1 # determine host name d146 1 a163 3 # determine domain name domainname='' @ 1.23 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1998-2000 Ralf S. Engelschall @ 1.22 log @*** empty log message *** @ text @a53 1 # the most important terminals we directly know d55 1 d64 22 a85 10 esac # then try a possibly existing "tput" or "tcout" utility paths=`echo $PATH | sed -e 's/:/ /g'` for tool in tput tcout; do for dir in $paths; do if [ -r "$dir/$tool" ]; then for seq in bold md smso; do # smso is last bold="`$dir/$tool $seq 2>/dev/null`" if [ ".$bold" != . ]; then term_bold="$bold" d89 2 a90 8 if [ ".$term_bold" != . ]; then for seq in sgr0 me rmso reset; do # 'reset' is last norm="`$dir/$tool $seq 2>/dev/null`" if [ ".$norm" != . ]; then term_norm="$norm" break fi done d92 3 a94 7 break fi done if [ ".$term_bold" != . -a ".$term_norm" != . ]; then break; fi done d238 1 a238 1 # awk complains about some \xx sequences. @ 1.21 log @*** empty log message *** @ text @d25 3 a27 1 opt_spec="ne" @ 1.20 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1998-1999 Ralf S. Engelschall @ 1.19 log @*** empty log message *** @ text @d231 1 a231 1 echo $seo $text d236 1 a236 1 echo $seo $minusn $text @ 1.18 log @*** empty log message *** @ text @d41 7 d230 7 a236 4 echo dummy |\ awk '{ if (OPT_N == "yes") NL = ""; d238 3 a240 3 NL = "\n"; printf("%s%s", TEXT, NL); }' TEXT="$text" OPT_N="$opt_n" @ 1.17 log @*** empty log message *** @ text @d69 1 a69 1 for seq in me rmso reset; do # reset is last @ 1.16 log @*** empty log message *** @ text @d64 1 a64 1 term_bold="$bold" d224 1 a224 1 awk '{ @ 1.15 log @*** empty log message *** @ text @d72 1 a72 1 term_norm="$norm" d229 1 a229 1 printf("%s%s", TEXT, NL); @ 1.14 log @*** empty log message *** @ text @d27 1 a27 1 . sh.common @ 1.13 log @*** empty log message *** @ text @d210 10 a219 10 sed -e "s;%B;${term_bold};g" \ -e "s;%b;${term_norm};g" \ -e "s;%u;${username};g" \ -e "s;%U;${userid};g" \ -e "s;%h;${hostname};g" \ -e "s;%d;${domainname};g" \ -e "s;%D;${time_day};g" \ -e "s;%M;${time_month};g" \ -e "s;%Y;${time_year};g" \ -e "s;%m;${time_monthname};g"` @ 1.12 log @*** empty log message *** @ text @d52 1 a52 1 term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); } /dev/null'` @ 1.11 log @*** empty log message *** @ text @d48 2 a49 2 term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' [ ...] d7 7 a13 12 # # command line parsing # newline="\n" expand=no while [ ".$1" != . ]; do case $1 in -n ) newline=""; shift; continue ;; -e ) expand=yes; shift; continue ;; * ) break ;; esac done a15 1 # a16 1 # a25 1 # a26 1 # d29 1 a29 1 if [ $expand = yes -a ".`echo $text | egrep '%[Bb]'`" != . ]; then d70 1 a70 1 echo "$0:Warning: unable to determine terminal sequence for bold mode" 1>&2 a73 1 # a74 1 # d76 1 a76 1 if [ $expand = yes -a ".`echo $text | egrep '%[uU]'`" != . ]; then a93 1 # a94 1 # d96 1 a96 1 if [ $expand = yes -a ".`echo $text | egrep '%U'`" != . ]; then a117 1 # a118 1 # d120 1 a120 1 if [ $expand = yes -a ".`echo $text | egrep '%h'`" != . ]; then a137 1 # a138 1 # d140 1 a140 1 if [ $expand = yes -a ".`echo $text | egrep '%d'`" != . ]; then a159 1 # a160 1 # d165 1 a165 1 if [ $expand = yes -a ".`echo $text | egrep '%[DMYm]'`" != . ]; then a191 1 # d193 1 a193 2 # if [ $expand = yes ]; then a206 1 # a207 1 # d209 2 a210 2 awk '{ printf("%s%s", TEXT, NEWLINE); }' \ TEXT="$text" NEWLINE="$newline" @ 1.5 log @*** empty log message *** @ text @d40 1 d51 26 a76 6 if [ ".$term_bold" = . -o ".$term_norm" = . ]; then md="`tput md 2>/dev/null`" me="`tput me 2>/dev/null`" if [ ".$md" != . -a ".$me" != . ]; then term_bold="$xmd" term_norm="$xme" d78 1 a78 1 fi @ 1.4 log @*** empty log message *** @ text @d168 1 a168 1 if test ".$time_year" = .; then d171 2 a172 2 9[0-9]*) time_year="19$time_year" ;; *) time_year="20$time_year" ;; @ 1.3 log @*** empty log message *** @ text @d42 2 a43 2 term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }'` term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }'` d46 2 a47 2 term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }'` term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }'` @ 1.2 log @*** empty log message *** @ text @d46 2 a47 2 term_bold=`echo dummy | awk '{ printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }'` term_norm=`echo dummy | awk '{ printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }'` @ 1.1 log @Initial revision @ text @d42 2 a43 2 term_bold=`echo dummy | awk '{ printf("%c%c%c%c", 27, 91, 49, 109); }'` term_norm=`echo dummy | awk '{ printf("%c%c%c", 27, 91, 109); }'` @ 1.1.1.1 log @Import of shtool 1.1.0 @ text @@