LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to write a shell script to simulate the built-in linux commands? (https://www.linuxquestions.org/questions/linux-general-1/how-to-write-a-shell-script-to-simulate-the-built-in-linux-commands-842865/)

linuxFreshMan 11-07-2010 08:55 AM

how to write a shell script to simulate the built-in linux commands?
 
Hi folks, i was trying to figure out a way to write my own linux commands.. in fact i wanted to write a shell script to simulate an already existed linux commands like 'cd','ls' and 'adduser'
i just dont know the language of scriptting and even doesnt know the steps to make a script.. please help..

stress_junkie 11-07-2010 09:09 AM

Such a request is too big for one thread.

There are several shells with different commands in Linux. You probably are referring to the bash shell.

Here is a starting point.
http://www.tldp.org/LDP/abs/html/

Some people get it and some don't. I fall into the second category. Some of the language syntax doesn't make any sense to me so I look for examples when I want to make a script.

teebones 11-07-2010 09:30 AM

as stated, first learn the shell itself. (e.g. BaSH)
then practice scripting, once you can make fairly complex scripts, without too much hassle, then you can go into what you want to do. (a lot of trickery is needed, to not invoke the real issued commands, like e.g. "rm -rf /" etc..)
another approach could be to write a program, which emulates the commands behavior, by faking it.
This can be done in, e.g. Python, Perl, C

yeugeniuss 11-09-2010 07:22 AM

As I understanded you need aliases. Alias allow you to run long command or script located somewhere by one command that you want.
Aliases are stored in .bashrc or .bash_profile files in your home directory.
open /home/your_user/.bashrc and write there alias. For ex I have next aliases in my .bashrc (some of them):

alias mysqld='/etc/init.d/mysqld'
alias telnetcmts='telnet 172.16.0.21'
alias delconf='~/bin/cleanbootfileconfig.sh'

If you want to know how to write your own scripts - download bash manual and perl for beginners and start to read it. Bash is good for small routine task (aka one line tasks), but not very powerfull (it is very slow if you have to operate with huge amounts of data). For real scripting task perl is much better and faster. Better to know both of them, of course.


All times are GMT -5. The time now is 05:32 PM.