LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   How-to set a parameter in the command line to be used later by a user-space script? (https://www.linuxquestions.org/questions/linux-kernel-70/how-to-set-a-parameter-in-the-command-line-to-be-used-later-by-a-user-space-script-4175452214/)

Didier Spaier 03-01-2013 04:35 AM

How-to set a parameter in the command line to be used later by a user-space script?
 
I understand that in the boot command line I can set parameters for the kernel and for kernel modules.

In addition, is it possible to set in the boot command line a parameter for a user space program or script?

For instance would it be possible to write something like "export LANG=fr" to be passed to some shell script after init or even rc.S is started?

elucches 03-01-2013 07:08 AM

You mean you can't use /etc/rc.local nor .bashrc?

a31amit 03-01-2013 08:03 AM

Here is the way :

Add your parameters in kernel line :

Code:

kernel /vmlinuz-2.6.18-308.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet myvalue=25
This will you can find in "/proc/cmdline" file while booting or after booting linux

Code:

[root@a31amit ~]# cat /proc/cmdline
ro root=/dev/VolGroup00/LogVol00 rhgb quiet myvalue=25

for getting values in script, you can use below mentioned code.
Code:


for params in $(cat /proc/cmdline); do
    echo $params | grep -q myvalue ;
    if [ $? == 0 ]; then
        val=$(echo $params | cut -d= -f2);
        echo "myvalue is $val";
    fi;
done

I believe this is what you want to know.

Didier Spaier 03-01-2013 08:11 AM

Quote:

Originally Posted by elucches (Post 4902374)
You mean you can't use /etc/rc.local nor .bashrc?

Thanks for your answer.

Your question makes me think that I should have given a bit more of context ;)

I am internationalizing Slackware's installer, thus the user should choose in which locale (s)he sees messages during the (text) installation.

There are basically two steps in the process:
(1) isolinux is used to provide the user with the ability of setting parameters in the boot command line, including which kernel to boot with (Incidentally, a that time (s)he can choose to boot an existing system instead of installing, and run testmem).
(2) Linux is booted, then the installation process occurs.

Basically I'd like that something I type in step (1) be used in step (2) so that the choice of UI's language be made really early.

PS I want to provide an internationalized installer, not several localized installers.

Didier Spaier 03-01-2013 10:02 AM

Quote:

Originally Posted by a31amit (Post 4902412)
Here is the way

Yes, that's exactly what I was looking for, Amit, thanks a lot! :cool:

PS Oh, and I almost forgot: welcome to LQ.

a31amit 03-02-2013 05:40 AM

@Didier, Thanks a lot :)


All times are GMT -5. The time now is 03:15 PM.