Hi,
When I run:
myword=`/`hostname`/scripts/checktbs.ksh /`hostname`/scripts/$USER"_apps.xdd"`
I receive:
ksh: /: 0403-006 Execute permission denied.
ksh: /scripts/checktbs.ksh: not found.
ksh: /scripts/user1_apps.xdd: not found.
For the permission , I have:
-rwxr-xr-x 1 user1 dba 617 Jun 18 18:52 /host/scripts/checktbs.ksh
Thanks for help.
Certainly the root cause (literally ) is
Check with
ls -ld /
The typical permission is 755 and can be restricted to 711 (but not 700).
One reason to have root's home directory in /root (not in / )
Hello,
One further thought here: do you perhaps have a space between the first /
and hostname
when you run the script ? In other words, are you typing:
/ hostname/scripts/checktbs.ksh
instead of:
/hostname/scripts/checktbs.ksh
If you are, that could well result in an error like the one you are reporting. I don't have an AIX system to hand to test on, so I don't know for sure what the IBM-style error you'd get in that situation is, but on Linux at least for the Korn shell I get a similar error:
$ / bin/ls
ksh: /: cannot execute [Is a directory]
$
1 Like
Hi,
Thank you.
There is no space between / and hostname but "`".
Take a look agin to my first post. For me it is a problem of:
`
For example this works:
ls /`hostname`/scripts/checktbs.ksh
/server/scripts/checktbs.ksh
But this does not work:
myword=`ls /`hostname`/scripts/checktbs.ksh`
ksh: /scripts/checktbs.ksh: not found.
Regards.
What is the reason/objective of having embedded backquotes?
if memory serves... You cannot embedd backquotes (unlike the $(...)
).
Try validating your script at shellcheck.net
1 Like
The outermost quotes (first and last backticks) must be plain double quotes "
.
The double quotes after USER are misplaced: remove them. They are actually quoting fixed text, not an expansion.
myword="/`hostname`/scripts/checktbs.ksh /`hostname`/scripts/$USER_apps.xdd"
Not sure how you plan to execute the result from myword -- it consists of a command and an argument. That is hard to quote in a safe way, too (using eval
is not recommended).
Backticks have been deprecated for decades. I would recommend:
Host=$( hostname )
Prog="/${Host}/scripts/checktbs.ksh"
Args="/${Host}/scripts/${USER}_apps.xdd"
and run it as "${Prog}" "${Args}"
I also have serious doubts that the full hostname is a valid pathname on most systems. "/${HOME}"
would be more usual.
2 Likes
In this case it ends the USER
(variable name).
I think ${USER}
is preferrable here.
Host=$( hostname )
myword=$(
"/$Host/scripts/checktbs.ksh" "/$Host/scripts/${USER}_apps.xdd"
)
1 Like
@MadeInGermany The quote does not end the user name, because there is no preceding quote. In the original post, there are only two double-quotes, and they surround the text "_apps.xdd"
. He probably stuffed those in because without them, it would have been evaluating an unknown variable $USER_apps
.
The backticks are also all complete the wrong way round, because the entire line is erroneously quoted with them too.
The reason it throws ksh: /: 0403-006 Execute permission denied.
is that the first thing on the command is backtick / backtick
, which attempts to execute the root directory itself. hostname
is plain text, then it tries to execute the next pair of backticks around /scripts/checktbs.ksh /
, and throws a "not found" error. The second hostname
is also plain text. And finally it tries to execute the backticks around /scripts/$USER"_apps.xdd"
and gets another "not found" error.
shellcheck throws three warnings SC2006: Use $(..) instead of legacy backticks
and one on $USER
as SC2086: Double quote to prevent globbing and word splitting.
This is not a permissions issue. The root /
is enclosed in back-ticks. Shell is not trying to read the contents of the directory, it it literally trying to run it as a process.
0403-006 is an AIX diagnostic. Linux flags this as: bash: /: Is a directory
, whether you run at as plain /
, or as $( / )
, or in back-ticks.
2 Likes
If you use $(command)
instead of `command`
, there will be less confusion.