isolated@alix.UUCP (20 James D. Corder) (10/02/90)
Mon Oct 1 13:20:32 EDT 1990 Hello NetPeople:-) I have a sh program that wants input at the command line. However, I need an error out if the unser does not input at the command line. ie: if [ ${1} = "" ] then echo "Please enter your option now." read $1 else echo "${1} was inputed at the command line" fi However, this file will get the following error message. jim: test: argument expected How can I do this? Thank you, James D. Corder ...osu-cis!alix!jdc ...att!osu-cis!alix!jdc alix!jdc@cis.ohio-state.edu
rouben@math13.math.umbc.edu (Rouben Rostamian) (10/02/90)
In article <311@alix.UUCP> isolated@alix.UUCP (20 James D. Corder) writes: > >I have a sh program that wants input at the command line. >However, I need an error out if the unser does not input at the command line. >ie: > >if [ ${1} = "" ] >then > echo "Please enter your option now." > ...etc... Replace the first line with: if [ "${1}" = "" ] --
gt0178a@prism.gatech.EDU (Jim Burns) (10/02/90)
in article <4053@umbc3.UMBC.EDU>, rouben@math13.math.umbc.edu (Rouben Rostamian) says: > In article <311@alix.UUCP> isolated@alix.UUCP (20 James D. Corder) writes: > >if [ ${1} = "" ] > Replace the first line with: > if [ "${1}" = "" ] Also beware of sh/ksh's '-u' (treat unset variables as an error). Use 'set +u' if necessary. -- BURNS,JIM Georgia Institute of Technology, Box 30178, Atlanta Georgia, 30332 uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0178a Internet: gt0178a@prism.gatech.edu
pavlov@canisius.UUCP (Greg Pavlov) (10/06/90)
In article <311@alix.UUCP>, isolated@alix.UUCP (20 James D. Corder) writes: > I have a sh program that wants input at the command line. > However, I need an error out if the unser does not input at the command line. > ie: Preset the variable with a string and then test to see if it was changed... greg pavlov, fstrf,amherst, ny
dmt@PacBell.COM (Dave Turner) (10/08/90)
In article <2919@canisius.UUCP> pavlov@canisius.UUCP (Greg Pavlov) writes: >In article <311@alix.UUCP>, isolated@alix.UUCP (20 James D. Corder) writes: >> I have a sh program that wants input at the command line. >> However, I need an error out if the unser does not input at the command line. Enclose the $1 in "s: L if [ "$1" = "" ] Without the quotes test sees just an equal sign and the "" -- Dave Turner 415/823-2001 {att,bellcore,sun,ames,decwrl}!pacbell!dmt
friedl@mtndew.Tustin.CA.US (Steve Friedl) (10/08/90)
> Enclose the $1 in "s: > > if [ "$1" = "" ] > While this handles the null input case properly, it can get confused if the variable contains one of the magic tokens for test (say, "-x" or "!"). Better is to de-magify [?] the variable with: if [ x"$1" = x"" ] so you don't get the potential surprise. Steve -- Stephen J. Friedl, KA8CMY / I speak for me only / Tustin, CA / 3B2-kind-of-guy +1 714 544 6561 / friedl@mtndew.Tustin.CA.US / {uunet,attmail}!mtndew!friedl "No job is too big, no fee is too big" - Gary W. Keefe's company motto
benah@adspp.uucp (Ben A. Hunsberger) (10/09/90)
In article <541@mtndew.Tustin.CA.US> friedl@mtndew.Tustin.CA.US (Steve Friedl) writes: >> Enclose the $1 in "s: >> >> if [ "$1" = "" ] >> > also suggested... > > if [ x"$1" = x"" ] > ok, excuse my ignorance but, wouldn't the following work just as well? if [ -z "$1" ] which is used to test if the variable is zero length? -- Benjamin A. Hunsberger | uunet!rutgers!iuvax!ndmath!nstar!adspp!benah MicroAge/Abacus | uunet!sco!romed!adspp!benah 2707 Middlebury St. | benah@adspp.UUCP Elkhart, IN 46516 | 219-295-4290 (voice) / 219-522-2964 (fax)