1

I have this part of the script(bash) that worked absolutely fine until recently but it throws me an error with file not found when using $1 to give directory path. Only difference I know is it stopped working after we upgraded to rhel 7.

here is the part of the script:

MOUNTINST=/opt/mqm80_Inst1

$1/crtMQdir.ksh $MOUNTINST/bin 755 mqm
$1/crtMQdir.ksh $MOUNTINST/logs 755 mqm
$1/crtMQdir.ksh $MOUNTINST/java/lib/soap 755 mqm

I am in the right directory path and also made sure the file exists:

   /var/mqm/trace/WMQUNX8000.02]
    $ ll *crt*
    -rwxr-xr-x. 1 mqm mqm 826 Apr 10  2014 crtMQdir.ksh

Here is the error I get:

./test5.sh: line 4: /crtMQdir.ksh: No such file or directory
./test5.sh: line 6: /crtMQdir.ksh: No such file or directory
./test5.sh: line 8: /crtMQdir.ksh: No such file or directory

Am I missing something ?

  • 3
    What command did you run that resulted in those errors? – thrig Jun 29 '17 at 20:45
  • 4
    You have to give directory path as an argument of test5.sh where those .ksh files are exists For example: ./test5.sh /home/abcd/bin – Sourav Jun 29 '17 at 20:53
  • 2
    You are, $1 is the first parameter, not the PWD. – Julie Pelletier Jun 29 '17 at 20:58
  • 3
    $1 inside the BASH script means the first argument to the script – Sourav Jun 29 '17 at 20:59
  • 1
    A quick echo in front of the offending line would have immediately told you what's trying to be done. – pfnuesel Jun 29 '17 at 22:45
1

Be sure to give the path as an argument for the script, as $1 is the first argument of the script.

If you want the path and the script name (complete path of the script, e.g /path/to/crtMQdir.ksh), you need to use $0 instead.

You also need to ensure that your ksh script has execution permissions: chmod +x /path/to/crtMQdir.ksh

An alternate way, if you want to run it from the current directory, is to simply replace $1 by $PWD in your current script. If you want it to use the same directory as the one to this script, you could also use $(dirname $0) instead of the $1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.