Need help with shell script

Can you or someone tell me what’s wrong with this simple script / bash?
Name of script is hpass.sh and it is located in /home
The script itself;
#!/bin/bash ----- also try #!/bin/sh
~/home/wdpassport-utils.py u
exit
~$ hpass.sh
hpass.sh: command not found
~$ hpass
hpass: command not found

1 Like

Can you post the clean script’s contents without the additional stuff? What is the script supposed to do?

1 Like

!/bin/bash
~/home/wdpassport-utils.py u
exit

I know it sound lazy, but I was trying to learn something too.
Instead of typing in terminal mode ‘sudo ~home/wdpassport-utils.py u’,
I wanted to just type ‘hpass’. The ‘u’ is a parm being pass to ‘wdpassport-utils.py’.
The command will unlock my WD external disk. It works fine, if I type it in with sudo in front of it.

1 Like

that’s not lazy at all. learning something new is the opposite of lazy in my book :slight_smile:

1 Like

as we have talked about, i don’t know anything about python. i do see one thing here:

your u needs a - in front of it = -u

then my question is whether or not you made your script executable. looks like you named it hpass.sh, so that command should look something like chmod +x ~/hpass.sh

1 Like

I’d suggest you need to preface calling your script with the path to the script, assuming $HOME is not on your $PATH - you have to explicitly tell it “run this script from this location” - with “./hpass.sh” - or “~/hpass.sh” - and also what somebody else suggested - make sure it’s executable “chmod +x ./hpass.sh”…

Also - most shells automatically append ~/bin/ onto your path if it exists - so make a folder ~/bin, copy the script there… if you want to ignore the .sh when you call it - make a symlink to the script “ln -s ~/bin/hpass.sh ~/bin/hpass”. You may have to log out and back in again if ~/bin didn’t exist and isn’t in your $PATH… once all that’s done - you can just type “hpass” as your shell now knows where to find that…

1 Like

alternatively - you could also create an alias to the python script -
alias hpass="~/home/wdpassport-utils.py u"

when you’re happy with that, assuming bash is your main shell (mine is zsh) then edit your ~/.bashrc and put that alias line at the end…

then all you have to do is type “hpass”…
— edit —
I just noticed something - you’re quoting “~/home/” is this true?

e.g. if your username is “easyt50”… is there a “/home/easyt50/home” folder ? Does this path exist? Maybe it should just be :

"~/wdpassport-utils.py"

or "/home/easyt50/wdpassport-utils.py"

2 Likes

Here again, I need some guidance. I don’t know any of the shell names or how many there are.
I need to walk (do something simple) first, before I run (writing something complex).
So I am willing to work with any shell. I would just like to use one that is easy to learn to start with.
For the time being, I want to write simple scripts to replace typing in a command or multi commands to help me use the PC.

1 Like

Yes, I missed type the command. A ‘-’ is required in front of the ‘u’. Thanks for noticing it.
I did the chmod and now when I edit the file, I get ‘hpass’ is an executable file.
I am still getting command not found when I type hpass in terminal mode.

1 Like

you probably have to add the “./” before you type the command :

e.g. “./hpass” (or “./hpass.sh”)

1 Like

Thanks for your suggestions. I believe I am at /home. If I do a dir, I can see my file ‘hpass.sh’.
I tried both way to exec the command (’./’ and ‘~/’ on front of ‘hpass.sh’.


easyt50@8300 ~ $ ./hpass.sh
./hpass.sh: line 2: /home/easyt50/home/wdpassport-utils.py: No such file or directory


easyt50@8300 ~ $ ~/hpass.sh
/home/easyt50/hpass.sh: line 2: /home/easyt50/home/wdpassport-utils.py: No such file or directory

Thanks Daniel, I just learn how to set up an alias and (look up) how to unalias. But that did not work either.


No, that file (dir) is not there. The path to the file is /home/easyt50/hpass.sh.

But I believe I see what you mean. ‘home’ is showing up too much, but I don’t know how to correct it.

1 Like

Bingo! :grinning: ‘./hpass.sh’ got the script to execute. It did not pick up the -u. So now I need to play around with passing a parm to the command from inside the script. I had to change the script by taking ‘home’ out of it. So the script now looks like this. Not the ‘*’, only the 3 lines.


#!/bin/bash
~/wdpassport-utils.py -u
exit


1 Like

When working directory is home than command must be
./hpass.sh

3 Likes

Thanks for your input and welcome to our community - hope you enjoy your stay with us

2 Likes