Command line arguments -- what form are they?
Im trying to take a command line argument that runs a shell script to use the argument as a command line argument for some perl code I am writing.
example: ./bash 5 start=$1; ./perl start; my $number=$ARGV[0]; In essence, perl is not seeing the argument as a number -- atleast I think thats whats going on. |
if your trying to pass the contents of the variable 'start' to perl, you have to dereference start: '$start'
|
And presumably it could just be:
./perl $1 To be clear, the above would be inside a bash script which is called using "scriptname 5". You don't want to call the actual bash shell and pass "5" to it....my hunch is that bash would not know what to do.... |
Also, no need to end every line with ';' in bash. Its only needed if you put multiple cmds on one line eg
if [[ $? -eq 0 ]]; then .... instead of if [[ $? -eq 0 ]] then ... |
It worked with the line
./perl $1 but I believe I had a bug in my perl code. Nonetheless, does bash interpret a command line argument as a string or does it dynamically determine what it should be by what you do with it say my command line argument was "happy" and "754", would bash know the first is a string and the second is a integer? |
something like hexdump is handy for showing how things are stored. In Bash, numbers are stored as strings...the interpretation depends on what commands are used.
try this: a=345 b=456 c=$((a+b)) echo $c c=$a$b echo $c |
Quote:
Code:
$var1 = 3; Code:
$var1 = 3; |
Brilliant! I had a look over the code you sent and believe I understand -- the context of what you do to the variable will define how it is classified by bash/perl, but for all intensive purposes, its originally stored as a string.
|
Quote:
|
All times are GMT -5. The time now is 01:00 AM. |