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..
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.
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.
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
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 telnetcmts='telnet 172.16.0.21'
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 09:59 AM.|