1.

Solve : Can I create a command with a system name?

Answer»

I'm relatively new to UNIX and am playing and experimenting. I would like to create a COMMAND in my home directory with the same name as a system command. For instance, I would like to create a ls  command.  I create a file named ls.  I edit it and put in one  echo  command.  I make the file executable, and I put my current directory and home directory as the first two in my PATH.  Yet when I issue the command:  ls I still get the system command.  Is there something else I need to do, or is it not POSSIBLE?
Thanks,
KenNo, don't do that. Use another name.
Try   lsx
Or maybe   kp

Why would you want to use a name that is already in use?
>> Why would you want to use a name that is already in use? <<

I'm strictly playing and experimenting. I guess I don't understand why, if I put my current directory as the first element in my PATH that it does not find my version of the ls command.  Nothing important for me just curiosity and learning.

Thanks,
~KenI'm a bit hazy on this, but if I recall correctly, ls is usually a shell internal command, so it's not actually SEARCHING your path.  Internal or built-in commands execute more quickly than external commands, so there's a slight PERFORMANCE advantage, compiling them into the shell.

If you want to change the effect of the ls command, use alias.  e.g.:

Code: [Select]alias ls="./ls"Using the alias command does not save the command for the next instance of terminal. Meaning you have to create a file in your /home/%username% directory. called .bash_aliases~ with the period in front of it and all

the contents should look like such

Code: [Select]alias ls="./ls"

I also added some costomizations to my own terminal, because this file seems to execute commands on the startup of terminal, therefore not making the alias command permanant, but configuring terminal to run it everytime at startup. So, upon my discovery of such, i put in some other commands in the file, like such

Code: [Select]echo Welcome to the Command Line on a computer of Jared Kat. Refer to the background for help
cal
uptime

alias minecraft="java -Xmx1024m -Xms1024m -jar /home/jaredkat/Downloads/minecraft.jar"

alias connect="ssh [email protected]"

You could play around with that a bit. Here is an item of interest.  The Ubuntu default shell was changed.
This is about why Ubuntu uses one shell and not another.
https://wiki.ubuntu.com/DashAsBinSh Quote from: Geek-9pm on March 26, 2012, 04:53:18 PM

Here is an item of interest.  The Ubuntu default shell was changed.
It's only used for scripts that specify a /bin/sh shebang, which is usually limited to scripts that start during the boot process.

Add to this the fact that that change happened 6 years ago...


Discussion

No Comment Found