LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-07-2010, 08:55 AM   #1
linuxFreshMan
Member
 
Registered: Nov 2009
Distribution: Ubuntu 9, RedHatLinux
Posts: 47

Rep: Reputation: 0
Unhappy 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..
 
Old 11-07-2010, 09:09 AM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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.

Last edited by stress_junkie; 11-07-2010 at 09:24 AM.
 
Old 11-07-2010, 09:30 AM   #3
teebones
Member
 
Registered: Aug 2005
Location: /home/teebones
Distribution: sometimes this, sometimes that..
Posts: 502

Rep: Reputation: 56
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
 
Old 11-09-2010, 07:22 AM   #4
yeugeniuss
LQ Newbie
 
Registered: Nov 2010
Posts: 4

Rep: Reputation: 0
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
New to linux and have a question about a shell script I'm attempting to write trace_effect Linux - Newbie 9 12-11-2009 01:23 AM
how to simulate the keystroke in shell script saurin Linux - General 1 09-15-2009 11:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration