I want to run my custom scripts but every time I need to execute it I have to type bash before the script name. But I want to run it just like we would run other scripts such as ls git sed chmod
etc where typing bash prior to the script name is not required.
I haven't found any solution here, but the closest was this Bash Script does nothing
I have created a script named test
#!/bin/bash
echo Hello
But when I type it on terminal it gives no error and prints nothing
user@notebook:~$ test
user@notebook:~$
But it works when I type it with bash
user@notebook:~$ bash test
Hello
user@notebook:~$
I have added the file to ~/.local/bin/
, given it the permission chmod a+x test
and ~/.local/bin
is set in my PATH
variable.
My stat /bin/bash
is
File: /bin/bash
Size: 1396520 Blocks: 2728 IO Block: 4096 regular file
Device: 806h/2054d Inode: 30408799 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-05-07 12:23:17.179593764 +0500
Modify: 2022-01-06 21:23:33.000000000 +0500
Change: 2022-10-08 20:47:19.225627603 +0500
Birth: 2022-10-08 20:47:19.217622335 +0500
My stat /bin
is
File: /bin -> usr/bin
Size: 7 Blocks: 0 IO Block: 4096 symbolic link
Device: 806h/2054d Inode: 12 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-05-07 12:22:43.299594371 +0500
Modify: 2022-10-08 20:47:18.020812502 +0500
Change: 2022-10-08 20:47:18.020812502 +0500
Birth: 2022-10-08 20:47:18.020812502 +0500
The output of type -a test
is:
test is a shell builtin
test is /home/saad/.local/bin/test
test is /usr/bin/test
test is /bin/test
/bin/bash
? Please include output ofstat /bin/bash
andstat /bin
. Also, which version of Ubuntu are you using? Thanks.which bash
and it returned/usr/bin/bash
. I have corrected that but still there is no change for me. My ubuntu version isUbuntu 22.04.2 LTS
. I have added thestat
output in my question.type -a myscript
?user@notebook:~$ bash myscript
What is the output ofreadlink -f myscript
?echo
... hence/bin/echo
and/usr/bin/echo
the external echo command ... Bash also has a builtinecho
... Had you used the actual script-file's name, it would've been a lot easier for you and us :-)