![]() |
2008-09-20
, 16:50
|
Posts: 5 |
Thanked: 0 times |
Joined on Sep 2008
|
#1
|
![]() |
2008-09-20
, 18:44
|
|
Posts: 4,930 |
Thanked: 2,272 times |
Joined on Oct 2007
|
#2
|
mpg321 file.mp3; run-standalone.sh dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.req_shutdown
![]() |
2008-09-20
, 18:46
|
Posts: 5 |
Thanked: 0 times |
Joined on Sep 2008
|
#3
|
![]() |
2008-09-20
, 18:52
|
Posts: 5 |
Thanked: 0 times |
Joined on Sep 2008
|
#4
|
![]() |
2008-09-20
, 18:59
|
|
Posts: 4,930 |
Thanked: 2,272 times |
Joined on Oct 2007
|
#5
|
#!/bin/sh mplayer file.mp3; run-standalone.sh dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.req_shutdown
chmod +x scriptfile
./scriptfile
The Following User Says Thank You to Benson For This Useful Post: | ||
![]() |
2008-09-20
, 19:01
|
|
Posts: 4,930 |
Thanked: 2,272 times |
Joined on Oct 2007
|
#6
|
![]() |
2008-09-20
, 19:33
|
Posts: 5 |
Thanked: 0 times |
Joined on Sep 2008
|
#7
|
![]() |
2008-09-20
, 22:43
|
|
Posts: 4,930 |
Thanked: 2,272 times |
Joined on Oct 2007
|
#8
|
The UNIX way is, among other things, to have the command interpeter (a shell) separated from the core OS (the kernel); in fact, the shell is just another process, on the same level as the database, document typesetter, or other apps. Another aspect of the UNIX way is that all* resources are abstracted as files; files that are abstractions rather than actual data on a disk are called special files, and mainly live in /dev/, though they can be created anywhere. One example of a resource that's a file is a system console (maybe /dev/tty0); writing data to it displays on the console's screen, and reading data from it gets data from the console's keyboard.** These two characteristics mean that a shell operates by reading commands from a file and writing output to a file. (These can be the same file, but don't have to be.) Normally, using a machine from the console, the shell would be reading from /dev/tty0, and writing to /dev/tty0, so you type commands and see the output.As for what you need to do:
But if you don't like typing commands repeatedly, you can put some commands you like into a file, and do something like
This starts a new shell process (we can do that, because it's separated from the kernel), but it will read from mycommandfile instead of the keyboard.Code:sh <mycommandfile
Since UNIX hackers are lazy (or efficient, depending how you look at it), it was desirable to add some way of executing such a script directly. Initially, this was implemented by the shell; if you tried executing something that wasn't a known binary format, the shell would try to interpret it as commands itself. That's not a clean solution, though, as the file may not be shell commands (maybe commands for some other process), there are different shells with different command sets, and it doesn't work if you try executing it any other way but a shell.
So Ritchie added the #! mechanism to the UNIX 8 shell (and it was carried from there to BSD 4.0, and eventually SVR4 (I think), and of course Linux), to let a script specify the right interpreter, and since this is in the kernel, scripts (shell, perl, or whatever) can be treated basically the same as binary executables. Adding the #! isn't strictly necessary, as a shell script without it will still run from the shell as in UNIX 7, but it can't hurt, because eve n on systems not supporting shebangs (or when typing it into the shell, as you did), starting with a # makes the line be treated as a comment, and ignored. That's why the chosen sequence started with a #.
*Actually, not quite all, but we're talking about the UNIX way, not about UNIX. It's a lot closer to all than other OSes.
**The tty stands for teletype, which were the canonical console devices. tty is now used generically for any character special file. An xterm uses a pty (psuedo-tty), which is a pair of special files with no associated hardware resource; the xterm uses one file, and the shell uses the other exactly the same as if it were a serial port, console, or other tty.
The Following User Says Thank You to Benson For This Useful Post: | ||
![]() |
2008-09-21
, 06:35
|
Posts: 5 |
Thanked: 0 times |
Joined on Sep 2008
|
#9
|