LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   small script (https://www.linuxquestions.org/questions/linux-newbie-8/small-script-392237/)

spx2 12-13-2005 02:48 AM

small script
 
im trying to make this small script to start up a
bunch of programs but i dont know how to make them
start simoultaneously not one by one waiting for
each other to be closed.




then i want to include that script to be exectuted
asking for permission somewhere but that would be simple...

for the first part i really cant get it done

Poetics 12-13-2005 02:54 AM

[command] &

The ampersand (&) tells the program to execute in the background, allowing foreground processes to continue while it runs.

So you could easily put as many commands as you need and have them start as close to sychronously as possible.

spx2 12-13-2005 03:01 AM

thanks
 
thanks man you've really been of help

is there any equivalent to autoexec.bat to linux ?
if there is how do i configure it to run my script
but that will be after kde starts because all programs
included in my script are using kde.
thanks again

Poetics 12-13-2005 03:13 AM

Every distro has a file that executes upon boot, ~/.bashrc or ~/.bash_profile execute when someone opens a terminal, and every WindowManager (KDE, Gnome, Fluxbox, et cetera) all have their own. They also have startup directories (or similar) that should be well-documented on both this and their own sites.

spx2 12-13-2005 03:25 AM

just partially solve the problem(partially because not yet tested)
i read from here kde docs and i would like to quoute them

that i have to put the scripts in my $KDEHOME/env/
and thats all i think

Quote:

10.10. How do I run a program at KDE startup?


There are many ways to do that. If what you want to do is to run some scripts that would set some environment variables (for example, to start gpg-agent, ssh-agent and others), you can put these scripts into $KDEHOME/env/ and make sure their names end in .sh. $KDEHOME is usually a folder named .kde (note the period at the beginning) in your home folder. If you want scripts to be executed for all KDE users, you can put them under $KDEDIR/env/, where $KDEDIR is the prefix KDE was installed to (you can find this out using the command kde-config --prefix).

spx2 12-13-2005 03:29 AM

how can i ask for user input in the script ?
like " Do you want the programs to start ? Y/N"
and do some ifs according to this
also how do i jumpexit from a bash script ?

spx2 12-13-2005 04:46 AM

script finsihed
 
i managed to pull this non-orthodox code out...
im not too familiar yet with bash shell scripting.
i used mcedit to code it.
it seems tought that if at line 1
i put "exitloop = 0" instead of
"exitloop=0" it tells me it cant find
program or function exitloop wich is rathre
weird.
at line 3 i've specified the programs i want it to
run.i like it allot now i dont know if it will be
displayed if i put it in $KDEHOME/env/ because
it must be displayed in order for the user to be able
to choose

Code:

#!/bin/bash

echo "------rapid startup program-----------"

exitloop=0;                            #line 1

until  [ "$exitloop" = "1" ]; do
read choice
    if [ "$choice" = "y" ]; then
        gaim & \
        /home/stef/Desktop/firefox/firefox &\
        sylpheed &\
        dcgui-qt
        echo "rapid startup-succes"    # line3
    else
        if [ "$choice" = "n" ]; then
        echo "nothing executed"
        exitloop=1;
        else
        echo "error at option input"
        fi
    fi
done

echo "------terminated-----------------------"


linmix 12-13-2005 11:43 AM

Quote:

Originally Posted by spx2
how can i ask for user input in the script ?
like " Do you want the programs to start ? Y/N"
and do some ifs according to this
also how do i jumpexit from a bash script ?

To have the script ask before doing something you need to use a combination of an 'if' and 'read' with echo to print the message:

Code:

echo "do you want to continue, yes or no"
read answer
if $answer=yes; then
    gaim&
fi

this will only start gaim if you type 'yes' after the question

If you want to learn more, the book in my sig (which can be downloaded free - but I like having it in paper format) and this tutorial are very useful.

linmix 12-13-2005 11:52 AM

Quote:

Originally Posted by spx2
i managed to pull this non-orthodox code out...
im not too familiar yet with bash shell scripting.
i used mcedit to code it.
it seems tought that if at line 1
i put "exitloop = 0" instead of
"exitloop=0" it tells me it cant find
program or function exitloop wich is rathre
weird.

not weird at all. To declaer a variable (which is what you are doing, you need to give the value of that variable with =.- If you leave a spacve you decalere it but don't give it a value. If you did "exitloop= 0" (notice the space after =) you set thwe variable to 'space'

spx2 12-13-2005 11:54 AM

i already managed to do that in my last post here
have you tried my script ?

linmix 12-13-2005 12:35 PM

yeah, got a bit carried away in my first post. The Until statement is nice but not necessary though. A simple 'exit 0' at the end of the script wouild have sufficed.


All times are GMT -5. The time now is 05:01 PM.