Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

script in $PATH hangs but not when using bash -x script-name

21 views
Skip to first unread message

jack...@gmail.com

unread,
Sep 10, 2016, 5:51:01 PM9/10/16
to
My $PATH includes ~/bin and inside ~/bin, I have an executable script owned by me. When I try to execute the script with ./script-name or bash -x script-name, it displays the usage as expected. However, if I execute it with just its name from any directory including ~/bin, it hangs. Is there is any way I can correct this? Thanks for any help.


#!/bin/bash
show_usage()
{
printf "%s\n" "aeb ra # pharaonic names ending in ra or re"
printf "%s\n" "aeb Akhenaten # search for a specific name"
exit 1
}

[ $# -eq 0 ] && show_usage
case $1 in
ra ) grep -h "r[ae]: hg =" $0 ;;
?* ) grep -v "^#" $0 |grep "$1" ;;
esac
exit 0

... the remainder of the file is all data

jack...@gmail.com

unread,
Sep 10, 2016, 5:52:52 PM9/10/16
to
I neglected to say that:

which script-name

finds only script-name

Ed Morton

unread,
Sep 10, 2016, 11:56:49 PM9/10/16
to
Sounds like your grep is hung waiting for a file name to operate on. Add echo
"<$0>" above the case statement and see what it says and add set -x to the top
after the shebang to trace what's being executed.

Ed.

Michael Paoli

unread,
Sep 13, 2016, 1:45:42 AM9/13/16
to
That's all nice and interesting, but:
You didn't show us what your PATH looks like.
e.g. a PATH of:
PATH=/foo:/bar~bin:/baz
wouldn't be of much use to execute stuff in ~/bin.
You also didn't show us the permissions on your script - you
mention: "executable", and "owned by me", but you don't specify by
what manner it is "executable" - is that permissions, or the data
content? There can also possibly be permissions issues with
directory or parent directories up the physical path.
Also, depending upon what happened and what order, and one's shell,
one might need to issue the "rehash" command or similar. If you fire
off a fresh shell, and that doesn't have the issue, that could be one
indicator that that may be the issue.

Icarus Sparry

unread,
Sep 13, 2016, 8:59:43 PM9/13/16
to
Great advice from Ed.
In addition it would be helpful if the OP could provide the version of
bash he is using, and the system type he is using. Also what he is using
to invoke his script (an interactive bash? zsh, another script, something
else).

I can not reproduce the problem with a Linux system running bash 4.3.46.




0 new messages