handling $1 in shell script directory path
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 ?
bash shell-script arguments cwd
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
|
show 3 more comments
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 ?
bash shell-script arguments cwd
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
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 oftest5.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 theBASH
script means the first argument to the script
– Sourav
Jun 29 '17 at 20:59
1
A quickecho
in front of the offending line would have immediately told you what's trying to be done.
– pfnuesel
Jun 29 '17 at 22:45
|
show 3 more comments
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 ?
bash shell-script arguments cwd
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 ?
bash shell-script arguments cwd
bash shell-script arguments cwd
edited Jun 30 '17 at 20:46
Gilles
539k12810911606
539k12810911606
asked Jun 29 '17 at 20:41
MO12MO12
81210
81210
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 19 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
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 oftest5.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 theBASH
script means the first argument to the script
– Sourav
Jun 29 '17 at 20:59
1
A quickecho
in front of the offending line would have immediately told you what's trying to be done.
– pfnuesel
Jun 29 '17 at 22:45
|
show 3 more comments
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 oftest5.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 theBASH
script means the first argument to the script
– Sourav
Jun 29 '17 at 20:59
1
A quickecho
in front of the offending line would have immediately told you what's trying to be done.
– pfnuesel
Jun 29 '17 at 22:45
3
3
What command did you run that resulted in those errors?
– thrig
Jun 29 '17 at 20:45
What command did you run that resulted in those errors?
– thrig
Jun 29 '17 at 20:45
4
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
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
2
You are,
$1
is the first parameter, not the PWD.– Julie Pelletier
Jun 29 '17 at 20:58
You are,
$1
is the first parameter, not the PWD.– Julie Pelletier
Jun 29 '17 at 20:58
3
3
$1
inside the BASH
script means the first argument to the script– Sourav
Jun 29 '17 at 20:59
$1
inside the BASH
script means the first argument to the script– Sourav
Jun 29 '17 at 20:59
1
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
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
|
show 3 more comments
1 Answer
1
active
oldest
votes
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
.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f374283%2fhandling-1-in-shell-script-directory-path%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
.
add a comment |
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
.
add a comment |
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
.
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
.
edited Jul 1 '17 at 1:24
Julie Pelletier
6,98011340
6,98011340
answered Jun 30 '17 at 22:35
oliviergolivierg
1012
1012
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f374283%2fhandling-1-in-shell-script-directory-path%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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 theBASH
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