1

I would like to pass parameters to a perl script using positional parameters inside a bash script "tablecheck.sh". I am using an alias "tablecheck" to call "tablecheck.sh".

#!/bin/bash
/scripts/tables.pl /var/lib/mysql/$1/ /var/mysql/$1/mysql.sock > /tmp/chktables_$1 2>&1 &

Perl script by itself works fine. But when I do "tablecheck MySQLinstance", $1 stays $1. It won't get replaced by the instance. So I get the output as follows:

Exit /scripts/tables.pl /var/lib/mysql/$1/ /var/mysql/$1/mysql.sock > /tmp/chktables_$1 2>&1 &

The job exits.

FYI: alias tablecheck='. pathtobashscript/tablecheck.sh'

I have a bunch of aliases in another bash script. Hence . command.

Could anyone help me... I have gone till the 3rd page of Google to find an answer. Tried so many things with no luck.

I am a noob. But may be it has something to do with it being a background job or $1 in a path... I don't understand why the $1 won't get replaced...

10
  • 1
    How are you invoking tablecheck? Post your script tablecheck.sh Commented Oct 27, 2013 at 5:20
  • It works fine for me, $1 is well expanded by the shell. Commented Oct 27, 2013 at 6:03
  • #!/bin/bash /scripts/tables.pl /var/lib/mysql/$1/ /var/mysql/$1/mysql.sock > /tmp/chktables_$1 2>&1 & Commented Oct 27, 2013 at 6:16
  • can you echo $1 in bash script? Cause $1 works fine for me Commented Oct 27, 2013 at 6:55
  • 2
    Please provide a minimal sh and Perl script that demonstrates the problem. I've just created a Perl script myscript.perl containing print "$ARGV[0]\n", a bash script myscript.bash containing ./myscript.perl "$1", and an alias alias myscript=". ./myscript.bash". Running myscript foo prints foo just fine, so the problem must be something in your script. Please strip it down to the minimum length that still exhibits the misbehavior, and post it here. Commented Oct 27, 2013 at 8:32

1 Answer 1

1

If I copy your exact set up (which I agree with other commenters, is some what unusual) then I believe I am getting the same error message

$ tablecheck foo
[1]+  Exit 127                /scripts/tables.pl /var/lib/mysql/$1/ /var/mysql/$1/mysql.sock > /tmp/chktables_$1 2>&1

In the /tmp/chktables_foo file that it makes there is an additional error message, in my case "bash: /scripts/tables.pl: No such file or directory"

I suspect permissions are wrong in your case

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.