You are not logged in.

#1 2011-12-29 20:08:58

nTia89
Banned
From: varese, italy
Registered: 2008-12-22
Posts: 1,230

[solved] bash script and terminal

hi to everybody,

i've done a simply script for automatically check package upgrade. then i launch it through a .desktop file

how can i do for opening a terminal when the script starts ???

the script is very simple:

#!/bin/bash
pacman -Syu

Last edited by nTia89 (2011-12-29 22:54:19)


+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome

Offline

#2 2011-12-29 20:10:48

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved] bash script and terminal

Try

#!/bin/bash
xterm -hold -e sudo pacman -Syu

Offline

#3 2011-12-29 20:52:59

nTia89
Banned
From: varese, italy
Registered: 2008-12-22
Posts: 1,230

Re: [solved] bash script and terminal

if a have more command in my script ???


+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome

Offline

#4 2011-12-29 20:55:45

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved] bash script and terminal

You can do

#!/bin/bash
xterm -hold -e /path/to/some/script

Offline

#5 2011-12-29 21:00:25

nTia89
Banned
From: varese, italy
Registered: 2008-12-22
Posts: 1,230

Re: [solved] bash script and terminal

but in this way i must make two script:

the first which contain my commands
and the second which launch it in a terminal

?!?!?!?


+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome

Offline

#6 2011-12-29 21:04:33

esa
Member
Registered: 2011-12-29
Posts: 143
Website

Re: [solved] bash script and terminal

Yeno...
You have the .desktop file wich calls the .sh script.
And you have the script itself... which calls up the new terminal and executes the command.

[Desktop Entry]
Name=(6) Games
Exec=/path/to/script
#!/bin/bash
pacman -Syu

Last edited by esa (2011-12-29 21:38:33)


Author of: TUI (Text User Interface for scripts), VHS (Video Handler Script, using ffmpeg) and YASSI (Yet Another Simple Script Installer)

Offline

#7 2011-12-29 21:20:28

nTia89
Banned
From: varese, italy
Registered: 2008-12-22
Posts: 1,230

Re: [solved] bash script and terminal

karol wrote:

You can do

#!/bin/bash
xterm -hold -e /path/to/some/script

if this is a script

and script (in /path/to/some/ ) contain command

scripts are two

plus the .desktop file

Last edited by nTia89 (2011-12-29 21:22:43)


+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome

Offline

#8 2011-12-29 21:25:06

dmartins
Member
Registered: 2006-09-23
Posts: 360

Re: [solved] bash script and terminal

The .desktop file can run xterm directly from the "Exec" key, including the additional parameters needed to make xterm run your script.

This way you have only one script and one .desktop entry.

Exec=xterm -hold -e /path/to/some/script

Offline

#9 2011-12-29 21:25:33

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [solved] bash script and terminal

nTia89 wrote:

but in this way i must make two script

Is that a problem?

Offline

#10 2011-12-29 21:34:28

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved] bash script and terminal

dmartins wrote:

The .desktop file can run xterm directly from the "Exec" key, including the additional parameters needed to make xterm run your script.

This way you have only one script and one .desktop entry.

Exec=xterm -hold -e /path/to/some/script

+1
I see there's also 'Terminal=true' setting available but don't know how exactly does it work and can't test it ATM. dmartins, would that setting open a terminal automatically? Would it also automatically close it?

Offline

#11 2011-12-29 21:54:20

Lars Stokholm
Member
From: Denmark
Registered: 2009-03-17
Posts: 223

Re: [solved] bash script and terminal

I use this as the first line in my script:

tty -s; [[ $? -ne 0 ]] && xterm -e $0

This will open the script in a terminal and you only need one script.

Edit: I guess this can be done even shorter: 'tty -s || xterm -e $0'. Lol.

Last edited by Lars Stokholm (2011-12-29 23:09:03)

Offline

#12 2011-12-29 22:38:58

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [solved] bash script and terminal

While I think there are already great answers above - particularly dmartins's, another alternative nTia, is to learn about here-documents.  Generally if you think you'd need two files, and you'd really rather only have one, there's a good chance you can make it work with a here-document.  Keep in mind one must be careful with these: different invocations process variables differently - but for me this is one of the coolest parts of shell scripting.

#!/bin/bash                                                                     
                                                                                
xterm -hold -e /bin/bash -c 'sh <<EOF                                           
#your script here ...
echo hello                                                                      
echo bye                                                                        
EOF                                                                             
'

Again, for the present purposes dmartins's answer is *much* better.  But if you want to experiment and learn, you can tinker with here-documents.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#13 2011-12-29 22:54:02

nTia89
Banned
From: varese, italy
Registered: 2008-12-22
Posts: 1,230

Re: [solved] bash script and terminal

dmartins and Lars Stokholm are what i need.

but i'm curious and i'll see that "here-documents"

thanks to everybody. [fully solved]


+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome

Offline

Board footer

Powered by FluxBB