Sponsored Content
Top Forums Shell Programming and Scripting $1 argument not being recognized Post 302542687 by Feliz on Thursday 28th of July 2011 10:28:44 AM
Old 07-28-2011
$1 argument not being recognized

I am working on AIX 6.1 issuing #!/bin/sh at the beginning of the script.

I don't understand why $1 is not working as expected. I expect it to hold the value for the first argument coming from the command line consistently - and it is not.

At the beginning of the script starting I do this:
Code:
echo "Number of arguments entered: $# "
echo $1
chk_date

When I echo $1 here it shows the output when the script is run:
Code:
Number of arguments entered: 1
07/28/2011

But when I do the same thing within the function chk_date() it won’t display it:
Code:
chk_date()
{

if [ "$1" != $TODAYDT ]
then
     echo "YOU ENTERED"
   echo $1     
     echo "TODAY IS ---> $TODAYDT"
     echo "YOU HAVE ENTERED A DATE THAT DOES NOT MATCH TODAY'S DATE"
     echo "DO YOU WANT TO USE TODAY'S DATE INSTEAD?  Y|y or N|n"
     read ANSWER

Script is excuted like this:
Code:
[doruatt01pu]/RRPS/devel/ora/mig: migmstr.sh_fc 07/28/2011

Full output
Code:
Number of arguments entered: 1
07/28/2011
YOU ENTERED

TODAY IS ---> 07/28/2011
YOU HAVE ENTERED A DATE THAT DOES NOT MATCH TODAY'S DATE
DO YOU WANT TO USE TODAY'S DATE INSTEAD?  Y|y or N|n


The first problem is that it is validating true as a non-match with the variable $TODAYDT which has the value of 07/28/2011 as shown in green.
See … below the YOU ENTERED in the output? It is blank – even though I’m doing the same echo command that displayed it as 07/28/2011 at the beginning of the script… I’m really stumped on this… please help. Thank you.

Last edited by radoulov; 07-28-2011 at 11:46 AM.. Reason: Code tags!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Argument not recognized as integer

I need to accept a number of arguments at command line and print it in reverse order i use eval `echo x=$1` to capture the argument #! /bin/sh counter=0 while do eval `echo x=$1` arg$counter=$x counter=`expr $counter + 1` shift done but the error keeps... (1 Reply)
Discussion started by: scmay
1 Replies

2. Forum Support Area for Unregistered Users & Account Problems

I am not being recognized

Hi Admin, My user id is "chanakyahere", i forgot my password. When i give my mail id "chanakyahere@gmail.com" it is not being accepting by webmaster. But to the same mail id i got reply to one of my questions. The same mail id i gave while registering in this site. This i can confirm as... (0 Replies)
Discussion started by: Help
0 Replies

3. UNIX for Dummies Questions & Answers

How to find the last argument in a argument line?

How to find the last argument in a argument line? (4 Replies)
Discussion started by: nehagupta2008
4 Replies

4. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

5. Solaris

New volume set not recognized

Good evening, I am fairly (re)new to Solaris 10. In fact I was even quite good at it, but that was about 10 years ago, so now I am back to beginner status :) I installed a new machine with an internal 16port RAID attached to an Areca 1260 controller. Also attached is an external SCSI-Raid. ... (7 Replies)
Discussion started by: PatrickBaer
7 Replies

6. Shell Programming and Scripting

File not recognized when passed as argument

I have the below script in file read_file.ksh if ] || ] then echo "Required one input file" echo "Enter a file to get char count:" read $FILE_NAME if ] then echo "valid file" else echo "Not a valid file." fi When run as read_file.ksh detail.csv or... (9 Replies)
Discussion started by: michaelrozar17
9 Replies

7. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

8. Shell Programming and Scripting

Second parameter is not recognized

Hey I have a problem with my script. I writing a script which can depend whether you want to make a file or a directory. I only give the code where you can find the problem. My loop doesn't stop and I don't know why and when i echo my second parameter , he echoes nothing :s Thnx ... (1 Reply)
Discussion started by: Eclecticaa
1 Replies

9. Shell Programming and Scripting

Alias not recognized within script

What would cause a script to work under one user account and not another? Here's an example of what I'm referring to. Here's a simple script. Let's put it in a file called “thescript”. #! /bin/bash alias a='echo hello world' a Here are the results when this script is executed logged in... (3 Replies)
Discussion started by: sszd
3 Replies

10. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 04:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy