LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 11-05-2007, 05:51 PM   #1
Registered: Dec 2005
Location: Bucharest, Romania
Distribution: Ubuntu 10.04
Posts: 38

Rep: Reputation: 15
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.
Old 11-05-2007, 06:00 PM   #2
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 13,132

Rep: Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260
Try something like
rlvl=$(runlevel | cut -f 2 -d " ")
Use $rlvl where needed.
Old 11-05-2007, 06:00 PM   #3
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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:
ls /etc/rc$(runlevel | cut -d" " -f2).d/S*
Old 11-06-2007, 12:24 AM   #4
Registered: Dec 2005
Location: Bucharest, Romania
Distribution: Ubuntu 10.04
Posts: 38

Original Poster
Rep: Reputation: 15
thanks. It works just fine


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
works on command line but not in bash script tara Linux - General 7 02-09-2009 03:57 AM
passing command line to a BASH function GSMD Programming 16 04-21-2007 03:23 AM
What bash command line utilities do I need? exl75 Linux - Newbie 8 04-16-2007 08:06 AM
bash, command line ftp, and a delimma.. scoob8000 Linux - Networking 2 03-18-2005 05:22 PM
bash shell command line expansion hansi umayangan Linux - General 2 03-13-2005 11:31 AM

All times are GMT -5. The time now is 06:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration