You are not logged in.
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
Try
#!/bin/bash
xterm -hold -e sudo pacman -Syu
Offline
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
You can do
#!/bin/bash
xterm -hold -e /path/to/some/script
Offline
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
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)
Offline
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
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
but in this way i must make two script
Is that a problem?
Offline
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
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
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
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