LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   One line command - bash (http://www.linuxquestions.org/questions/linux-general-1/one-line-command-bash-597355/)

da_marius 11-05-2007 06:51 PM

One line command - bash
 
Not sure if this is the right section for this question


I need a one-liner for this task: print the scripts that are being run at the begining of the current runlevel.

so fare I have
runlevel | cut -f 2 -d " "

Next, I need a ls, but I don't know how to set the path parameter to
/etc/rcx.d/ where x is the number that is displayed when using the runlevel | cut command.
Please help.

syg00 11-05-2007 07:00 PM

Try something like
Code:

rlvl=$(runlevel | cut -f 2 -d " ")
Use $rlvl where needed.

matthewg42 11-05-2007 07:00 PM

You can take the result of a command and use it in another using either `backticks` or $(like this). I favour the $() syntax because it less likely to lead to a mistake (i.e. using the wrong type of quote), and is nestable.

The programs which will be run for a given runlevel are the ones with S at the start of the file name, so if you want to list the files which are executed, you can do it like this:
Code:

ls /etc/rc$(runlevel | cut -d" " -f2).d/S*

da_marius 11-06-2007 01:24 AM

thanks. It works just fine


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