Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"set -m" command in shell script

I was going through a shell script where set -m was used.
My understanding is that set is used to get positional args.

For ex: set "SO community is very helpful". Now, if I do echo $1, I should get SO and so on for $2, $3…

After checking the command with help flag, I got "-m Job control is enabled."

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My question is, what is the purpose of set -m in the following code?

set -m 
(
    current_hash="some_ha54_one"
    new_hash=$(cat file.txt)

    if [ $current_hash -ne new_hash ]; then
        pip install -r requirement.txt
    fi

    tmp="temp variable"
    export tmp

    bash some_bash_file.sh &
    
    wait
    
    bash some_other_bash_file.sh &
)

I understand (to the best of my knowledge) what I going on inside () but what is the use of set -m ?

>Solution :

"Job control" enables features like bg and fg; signal-handling and file-descriptor routing changes intended for human operators who might use them to bring background tasks into the foreground to provide them with input; and the ability to refer to background tasks by job number instead of PID. The script segment you showed doesn’t use these features, so the set -m call is presumably pointless.

These features are meant for human users, not scripts; and so in scripts they’re off by default. In general, code that attempts to use them in scripts is buggy, and should be replaced with code that operates by PID. As an example, code that runs two scripts in parallel with each other, and then collects the exit status of each when they’re finished without needing job control follows:

bash some_bash_file & some_pid=$!
bash some_other_file & some_other_pid=$!
wait "$some_pid"; some_rc=$?
wait "$some_other_pid"; some_other_rc=$?
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading