-1

I'm trying to do my own command (test.sh script).

The script works perfect and I created a soft link (i.e., ln -s /home/test.sh ~/bin/test).

And when I call from anywhere inside RHEL, it also works perfectly.

But my problem is the next one:

When from the command line I'm writing the name of the command (test), and I press the Tab key, the system shows me the full path and name of my script, i.e., $ /home/bin/test, and I want that it only shows me the name of the command ($ test).

Is that possible? How can I do it?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
sigsag
  • 37
  • 8
  • Maybe you have the readline "expand tilde" option enabled – you can check with `bind -V | grep 'expand-tilde'`. If it is set to `on`, you can add `set expand-tilde off` to your `~/.inputrc`; to check if it worked, start a new login shell or reload the configuration (typically with Ctrl-X-R), make sure the `bind` command from above shows now `off`, then try tab completion. – Benjamin W. Sep 16 '19 at 12:58
  • sorry, but I tried "bind" and on RHEL is saying me "bind: not found". – sigsag Sep 16 '19 at 14:07
  • What's the output of `type bind`? – Benjamin W. Sep 16 '19 at 14:20
  • $ bind $ -ksh: bind: not found [No such file or directory] – sigsag Sep 16 '19 at 14:23
  • 1
    your cmd shell is `ksh`, not `bash`. Can you switch to `bash`? I don't think `ksh` has a`bind` cmd. Good luck. – shellter Sep 16 '19 at 14:33

2 Answers2

0

If you want to make your own commands and have them tab-complete without browsing to their directory you would begin by looking at your $PATH variable

echo $PATH

This should return a list of variables in your current path if you want to edit your path click here

I may suggest a common place location for your link in /usr/bin

Certain distributions will often include ~/bin in their $PATH, using this location may or may not explain why your tab-complete is completing the full and not just the command

ln -s /home/test.sh /usr/bin/test

Also, you may want to consider as a personal preference utilizing the /opt directory to keep things organised, for example

ln -s /opt/scripts/test.sh /usr/bin/test

Steve
  • 119
  • 5
  • Ok, thank you for you support. Well, my directory was on $PATH. I'll check your suggestions. Thanks. – sigsag Sep 16 '19 at 14:45
-1

What you need is an alias. In RHEL/CENTOS systems, perform the below steps

  1. vi ~/.bashrc
  2. add this line alias test='/home/test.sh'
  3. source ~/.bashrc (optional step, unless you want your current session to have the updated bashrc, else a restart/logout/login should not require this step!)
garlicFrancium
  • 2,013
  • 14
  • 23
  • Sorry, but I don't understand step nº3. I've got the next messages when I executed. -ksh: .[5]: .[37]: shopt: not found [No such file or directory] -ksh: .[5]: .[38]: hist: -a: unknown option Usage: hist [-lnprs] [-e editor] [-N num] [first [last] ] -ksh: .[5]: .[40]: shopt: not found [No such file or directory] -ksh: .[5]: .[51]: shopt: not found [No such file or directory] – sigsag Sep 16 '19 at 14:06
  • what shell are you using? also try again without bash in step 2 which would be `alias test='/home/test.sh'` Also make sure you have executable permission on the file `test.sh` which is `chmod +x test.sh` – garlicFrancium Sep 16 '19 at 14:13
  • 1
    Ok, now It works. I deleted the text "bash" and also I've wrote the path exactly where the test.sh was. I was specificaing the path with "ln" (softlink) – sigsag Sep 16 '19 at 14:33
  • Also note you had to do Step 3 so that the bashrc takes into effect in the current logged in session but for future when you reboot/start/logout and login then the source won't be necessary! FYI – garlicFrancium Sep 16 '19 at 14:57