Bharath Tupaki
Bharath Tupaki

Reputation: 35

Unable to pass parameters to a perl script inside a bash script

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...

Upvotes: 1

Views: 202

Answers (1)

Vorsprung
Vorsprung

Reputation: 34297

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

Upvotes: 1

Related Questions