LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-12-2002, 03:45 PM   #1
rooman
Member
 
Registered: Mar 2002
Location: Lausanne, Switzerland
Distribution: Mandriva 2007.0
Posts: 223

Rep: Reputation: 30
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.
 
Old 06-12-2002, 03:56 PM   #2
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
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
 
Old 06-12-2002, 05:16 PM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,396

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
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.
 
Old 06-13-2002, 08:28 AM   #4
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 64
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.
 
Old 06-13-2002, 08:38 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,396

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
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.
 
Old 06-13-2002, 03:20 PM   #6
rooman
Member
 
Registered: Mar 2002
Location: Lausanne, Switzerland
Distribution: Mandriva 2007.0
Posts: 223

Original Poster
Rep: Reputation: 30
Thanks for your comments guys, I'm going to look at this over the weekend.
 
Old 01-31-2006, 10:38 AM   #7
shandy^^^
LQ Newbie
 
Registered: Jan 2006
Posts: 26

Rep: Reputation: 15
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
 
Old 01-31-2006, 11:16 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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
 
Old 01-31-2006, 11:16 AM   #9
Dtsazza
Member
 
Registered: Oct 2005
Location: Oxford, UK
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Posts: 282

Rep: Reputation: 30
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)?
 
Old 01-31-2006, 11:21 AM   #10
Dtsazza
Member
 
Registered: Oct 2005
Location: Oxford, UK
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Posts: 282

Rep: Reputation: 30
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...
 
Old 01-31-2006, 11:30 PM   #11
shandy^^^
LQ Newbie
 
Registered: Jan 2006
Posts: 26

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

Last edited by shandy^^^; 01-31-2006 at 11:31 PM.
 
Old 02-01-2006, 03:31 AM   #12
Dtsazza
Member
 
Registered: Oct 2005
Location: Oxford, UK
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Posts: 282

Rep: Reputation: 30
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... )
 
Old 02-01-2006, 06:22 AM   #13
shandy^^^
LQ Newbie
 
Registered: Jan 2006
Posts: 26

Rep: Reputation: 15
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.
 
Old 02-01-2006, 07:57 AM   #14
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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....
 
Old 02-02-2006, 07:49 PM   #15
shandy^^^
LQ Newbie
 
Registered: Jan 2006
Posts: 26

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
List of console commands? Mill Linux - General 4 01-06-2006 02:13 AM
Console (terminal) Commands ? sonsuzuncu Linux - Newbie 3 10-27-2005 06:31 PM
more access?///console commands chiatello Linux - General 6 07-13-2003 02:46 PM
Disabling console commands? Kage Linux - Newbie 4 02-09-2002 12:38 PM
Console Commands. Madmanator Linux - General 1 01-24-2002 02:10 PM


All times are GMT -5. The time now is 03:08 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration