LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   console commands as script? (http://www.linuxquestions.org/questions/linux-newbie-8/console-commands-as-script-23272/)

rooman 06-12-2002 03:45 PM

console commands as script?
 
I'm looking to write command line commands as a script to be executed by launching the file from an icon or double click etc. Do I need to look at .sh files and bash?
I'm thinking about saving energy on launching programs with Wine.

llama_meme 06-12-2002 03:56 PM

Ok, this is easy. First make your shellscript file:

-- start --
#!/bin/sh
# This is a comment because the line starts with a hash
[your commands here]
-- end --

Say that file was called foo.sh, now do:

chmod +x foo.sh

You can now run foo.sh just like a normal executable.

Alex

acid_kewpie 06-12-2002 05:16 PM

incidentally you don't need to call it something.sh. that's only an occasional convention. you'd be suprised how many commands you use are actaully just script files. also you don't need to use the #!/bin/sh line either, as that is the default used to interpret a script file, but that is a good habit to get into tho.

MasterC 06-13-2002 08:28 AM

Ok, so I would just open an editor and type
mplayer -[options]

and make it executable and that's it? It seems like a symlink would be more appropriate then? What am I missing? Obviously I am just trying to read into this ain't I.

acid_kewpie 06-13-2002 08:38 AM

you can't make a symlink including options. you presumably mean making an alias. it all depends what you want to do with a scripts as to how much goes into it. you COULD have a script that just did that but it'd be a bit pointless.

rooman 06-13-2002 03:20 PM

Thanks for your comments guys, I'm going to look at this over the weekend.

shandy^^^ 01-31-2006 10:38 AM

I want to make script where when it will be click it will issue a command in the terminal. the file is a perl file. what shall i do?

pls help me.

thanks

pixellany 01-31-2006 11:16 AM

Quote:

Originally Posted by rooman
I'm looking to write command line commands as a script to be executed by launching the file from an icon or double click etc. Do I need to look at .sh files and bash?
I'm thinking about saving energy on launching programs with Wine.

Writing shell scripts has little to do with running programs on Wine....
Shell scripts operate at the shell-level, and are barely above assembly language.
Wine is for running high-level Windows apps on Linux.

Go to www.tldp.org and get the "Bash Guide for Beginners" by Machtelt Garrels

Dtsazza 01-31-2006 11:16 AM

First, you're better off starting your own thread that jumping on the end of someone else's, for a variety of reasons (including that threads with no replies get auto-bumped and thus more attention)...

Secondly, your description is a little vague. You're talking about terminals and clicking on things in the same context, whereas they're usually pretty separate. If you click on something, it's usually up to the Window Manager to decide what to do in that situation based on a variety of things, so it depends which WM is running and what it's looking for. Generally when the WM decides to do something based on a GUI event, it won't direct the output to a particular terminal since any xterm (for example) that you launch is just its own program sitting on the desktop. You can probably instruct it to run the program in a terminal, but I'm second-guessing you here...

Let's start again. You have a perl file. How is it you expect the user to start it running (clicking on it or issuing a console command), and what output do you want to happen (and where)?

Dtsazza 01-31-2006 11:21 AM

Quote:

Originally Posted by pixellany
Writing shell scripts has little to do with running programs on Wine....

Yes. In this instance, you probably are better off with an alias if all you want to do is shorten the command to, say, 'cs' instead of giving all the arguments to launch wine running Counter-Strike. However, if there's certain environment variables you need to set, other pre-launch things to be done (especially if only under certain conditions) then a shell script may earn its keep.

Quote:

Originally Posted by pixellany
Shell scripts operate at the shell-level, and are barely above assembly language.

Oooh... I wouldn't quite go that far. That's like saying that working from a console is barely above feeding machine code instructions to the processor by hand... ;)

shandy^^^ 01-31-2006 11:30 PM

Hello.

I tried the konsole command like I have a
--------------
#file1

#!/bin/sh
konsole --vt_sz 80x40 -noclose --workdir /etc/file/ -e file2
--------------
#file2

#!/bin/sh
echo "Hello! This should display"

--------------

chmod +x file1
chmod +x file2

./file1

After ./file1 a blank terminal/konsole would just popup.
am i doing it right? I want that the when i do the ./file1 it would display on the terminal ka output of file2. is posible?

Whats the use of this line "konsole --vt_sz 80x40 -noclose --workdir /etc/file/ -e file2" ?

Pls help me.

Thanks.

Dtsazza 02-01-2006 03:31 AM

I'm not really sure what those arguments do (perhaps Virtual Terminal size = 80 by 40 pixels, don't close on exit, work in the /etc/file directory and execute 'file2'?) - but
Code:

man konsole
will tell you for sure. My guess as to why the second script isn't running is the --workdir /etc/file; perhaps the konsole is starting up in that directory, so it tries to look there for file2? You could try fully qualifying the filename (e.g. ~/test/file2 instead). Just to check, are there any messages at all on the new konsole or does it just go straight to a prompt?

(I have ideas of getting this to work involving creating a new user specially and playing with their ~/.bashrc files. I know it's actually crazy, but it's always nice to know how you can connect up your toolkit in Linux... :cool: )

shandy^^^ 02-01-2006 06:22 AM

Im using Fedora Core 4 and it cant locate the manual for konsole.

In the new konsole it is only blank and there is no prompt.

pixellany 02-01-2006 07:57 AM

Quote:

Originally Posted by Dtsazza
Oooh... I wouldn't quite go that far. That's like saying that working from a console is barely above feeding machine code instructions to the processor by hand... ;)

I am aware that I spoke imprecisely...the sense of my comment was that shell programming can involve some pretty crude, non-intuitive syntax. A long series of nested sed commands, for example, will be absolutely incomprehensible to the average programmer.
Like C, shell programming takes you closer to the guts than some other languages. But, yes, its not the same as assembler....;)

shandy^^^ 02-02-2006 07:49 PM

I tried the konsole command and this script but it would just popup a new blank terminal :

#!/bin/bash
konsole --noclose -e echo_args Hello, thanks for using Konsole!

the other terminal it would display like this:

[root@client1 sample]# ./file1
Uh oh.. can't get terminal attributes..


All times are GMT -5. The time now is 09:07 PM.