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: 107/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
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 12:46 PM..
Reason: Code tags!
It has something definitely to do with the echo $1 being inside the function chk_date(). I modified the script so that it would not have the function chk_date() and it works as expected:
Code:
[doruatt01pu]/RRPS/devel/ora/mig: migmstr.sh_fc 07/28/11
Number of arguments entered: 1
06/28/2011
YOU ENTERED
06/28/2011
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
So, I’d like to know why a custom function changes the functionality of the $1 when used within that function. Thanks!
Last edited by radoulov; 07-28-2011 at 01:05 PM..
Reason: Code tags.
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)
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)
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)
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)
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)
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)
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)
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)
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)