Bash script argument problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Bash script argument problem
# 1  
Old 01-13-2009
Bash script argument problem

I'm having problems with bash scripts. If a bash script is called with no arguments, I always get "PHIST=!" as the first argument (i.e. this is what $1 equals). Why? Where does this come from, and how can I fix it? Nothing in the bash man pages refer to this mysterious default argument.
# 2  
Old 01-14-2009
That is very strange. I would say it's not supposed to be there. Try the following:
Code:
set -v -x

Now invoke the script. Post the output.
# 3  
Old 01-14-2009
Thanks for the reply, but I found the problem.

My environment variable BASH_ENV was set to my bash resource file. This means that non-interactive scripts are going to call my bash resource file when they are executed. It turns out that my bash resource file was calling a common bash resource file that was supplied by someone on our project for everyone to use. It is suppose to provide some basic settings. Unfortunately this common resource file was patterned after a common csh resource file for our csh users. The problem was that some of the set commands in the csh file were not changed appropriately for the bash file. The last of these set commands was the following...

set PHIST=!

This is strictly a csh setting anyway. However, according to the bash man page, any remaining arguments after the options are processed (and you can see there were no options in this command) are treated as values for the positional parameters, and are assigned accordingly. Therefore, $1 was set to PHIST=!.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash argument not expanding in script

I pass an argument to bash as run. The first command in green executes as expected, however the second in blue fails as the $run does not expand. I tried to escape the variable with \ thinking the quotes were making the literal translation and also "${run}" but both did not work to expand the... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

checking first argument for tag in bash script

I have a bash script where I pass an argument ./chris.bash "\argv Test" I want to detect if the user supplied \argv at the start of the argument (3 Replies)
Discussion started by: kristinu
3 Replies

3. Shell Programming and Scripting

bash script argument not outputing line -NULL

Hi everybody! I am writing a script which accepts two arguments one of them being a message. All is working except for the message part. That is, to accept text as an argument. I have trouble storing and echoing a line of text. It seems that writing a few words and store them in an... (6 Replies)
Discussion started by: bluetxxth
6 Replies

4. Shell Programming and Scripting

Problem in bash script

I have written a script and I get error and I don't understand why. neededParameters=2 numOfParameters=0 correctNum=0 while getopts "s:l:" opt do case "$opt" in s) serviceName= $OPTARG #errorline 1 numOfParameters= $numOfParameters + 1 ;; l) ... (12 Replies)
Discussion started by: programAngel
12 Replies

5. Shell Programming and Scripting

How to use perl to run bash with argument?

Hi All, I want to run a bash script using perl. But they are in the different dir. #! /usr/bin/perl -w use strict; my $root=`pwd`; chomp($root); my $cmd=".$root/testdir/ft_623.sh 3 4 5 6 7"; print $cmd; my @line=`$cmd`; foreach (@line){ print $_; } ft_623.sh (0 Replies)
Discussion started by: Damon sine
0 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

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

8. Shell Programming and Scripting

check if argument is an ip address in bash/sh

Hi all, Can you please suggest a few lines of if statement to check if a variable is an ip address purely in bash/sh? Thanks, Marc (3 Replies)
Discussion started by: marcpascual
3 Replies

9. Shell Programming and Scripting

Problem when passing argument to a shell script

Hi all, I'm new to Shell scripting. In my shell script for Bourne shell, the script accepts a date parameter which is optional. If the value is supplied, the supplied value should be assigned to a variable. If not, the current date will be assigned to the variable. My script is like this. #!... (9 Replies)
Discussion started by: sumesh.abraham
9 Replies

10. Shell Programming and Scripting

bash script problem

hi I am writing a bash script that uses dialog to get user input an diplay messages to user. I have a small problem dialog --inputbox "blabla" 20 50 2> /tmp/output VAR="'cat /tmp/output'" mkdir $VAR the code below requests user for a directory path to be created. But, if the user uses... (1 Reply)
Discussion started by: fnoyan
1 Replies
Login or Register to Ask a Question