Passing argument not retrieving.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing argument not retrieving.
# 1  
Old 10-23-2015
Passing argument not retrieving.

Hi
I have a script which am trying to pass an argument which am trying to call using $1 but its not taking the value inside the if loop as it showing the error as if: Empty if..
Any help on this will be helpful.



Code:
#!/usr/bin/csh
echo $1
if ('$1' == "pp")
then
echo "Printing $1"
endif

rogerben
# 2  
Old 10-23-2015
man csh:
Quote:
Variable substitution is suppressed inside of single quotes
---------- Post updated at 17:13 ---------- Previous update was at 17:12 ----------

But that wouldn't explain the "Empty..." message. Does it echo $1 correctly?
# 3  
Old 10-23-2015
Quote:
Originally Posted by RudiC
man csh:

---------- Post updated at 17:13 ---------- Previous update was at 17:12 ----------

But that wouldn't explain the "Empty..." message. Does it echo $1 correctly?
yes echo $1 working fine.
rogerben
# 4  
Old 10-23-2015
Quote:
Originally Posted by rogerben
Hi
I have a script which am trying to pass an argument which am trying to call using $1 but its not taking the value inside the if loop as it showing the error as if: Empty if..
Any help on this will be helpful.



Code:
#!/usr/bin/csh
echo $1
if ('$1' == "pp")
then
echo "Printing $1"
endif

The csh syntax is a bit different. Try:


Code:
#!/usr/bin/csh
echo $1
if ($1 == "pp") then
    echo "Printing $1"
endif

# 5  
Old 10-26-2015
Code:
#!/usr/bin/csh
echo $1    ---> Value printing
if ($1 == "pp")
then
echo "Printing $1"
endif

I tried the same code but still am getting the error like "if: Empty if"
rogerben
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing a second argument

I am trying to pass a second argument like so: if ] then export ARG2=$2 else message "Second argument not specified: USAGE - $PROGRAM_NAME ARG1 ARG2" checkerror -e 2 -m "Please specify if it is a history or weekly (H or W) extract in the 2nd argument" fi however, it always goes... (4 Replies)
Discussion started by: MIA651
4 Replies

2. Shell Programming and Scripting

Argument passing

How to pass the alphabet character as a argument in case and in if block? ex: c=$1 if a-z ]] then echo "alphabet" case $1 in a-z) echo "the value is a alphabet" edit by bakunin: please use CODE-tags. We REALLY mean it. (9 Replies)
Discussion started by: Roozo
9 Replies

3. Shell Programming and Scripting

Help with passing argument

Hi, I have a script that is scheduled with cron and runs every night. The cron part looks like this: 00 20 * * 0,1,2,3,4,5,6 /usr/local/bin/BACKUP TBTARM HOT DELETE My issue is with the 3rd parameter. Somewhere in the script, i want to tell the script to delete some files if the 3rd... (7 Replies)
Discussion started by: dollypee
7 Replies

4. Shell Programming and Scripting

Recursive argument passing

I'm writing a script that can be called on itself, and must be able to pass arguments down to itself properly. The regular usage of the script is as follows: myfun cmd1 'options1' cmd2 'options2' input If you're interested, the nuts and bolts of this function simply compare the outputs of... (2 Replies)
Discussion started by: Sunlis
2 Replies

5. Shell Programming and Scripting

Help with Passing argument and testing

Hi all First of all thanks for everyone to read by doubt.Am beginner in shell scripting Following are my doubts i have to pass an argument to shellscript how can i do that second i have to test the argument and shows error when nothing is passes third i have to match exact argument... (3 Replies)
Discussion started by: zeebala1981
3 Replies

6. Shell Programming and Scripting

Using GET, passing argument to bash

Hi guys! So, I use GET ( Simple user agent using LWP library. ) on a remote text file that is then passed to bash and executed. However, I need to pass that bash script a single argument, and so far nothing that I have tried has worked, although I have learned quite a bit about input/output... (5 Replies)
Discussion started by: Rhije
5 Replies

7. Shell Programming and Scripting

passing Argument

Hi All, i have script like below.. echo "1) first option" echo "" echo "2) second option" echo "" echo "*) please enter the correct option" read select case $select in 1) echo "first option selected" ;; 2) echo "second option selected" ;; *) echo "please enter the correct... (4 Replies)
Discussion started by: Shahul
4 Replies

8. Shell Programming and Scripting

Problem in argument passing

Hell all, i have a problem in argument passing. print() { a=$1 b=$2 c=$3 echo $a echo $b echo $c } x="1 2 3" y="4 5 6" z="7 8 9" print $x $y $z. (4 Replies)
Discussion started by: tsaravanan
4 Replies

9. Shell Programming and Scripting

Problem with Argument Passing

Greetings, I am wrapping the monitoring commands like vmstat, sar, iostat and call via arguments I want ./unix_stats.sh -v vmstat -p <SEC> -d <Duration> to give vmstat values, and similarly iostat etc.,. Also if I give ./unix_stats.sh -v vmstat -i iostat -p <SEC> -d <Duration> should give... (4 Replies)
Discussion started by: A_Rod
4 Replies

10. Programming

Thread Argument Passing

#include <stdio.h> #include <pthread.h> #define NUM_THREADS 4 /* function to be executed by the new thread*/ void *PrintHello(void * threadid) { printf("\n %3d:Hello World!\n",threadid); pthread_exit(NULL); } int main(int argc, char * argv) { int *taskids; int... (2 Replies)
Discussion started by: narom
2 Replies
Login or Register to Ask a Question