skip to Main Content

How can i run a bash script from new environment?

I try to do it like this, but its not working

#!/bin/bash

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/dell/srvadmin/sbin:/root/bin"

racadm getsvctag > /root/Desktop/serialTest.txt

2

Answers


  1. You can run your bash script in a new environment if you replace your shebang line with:

    #!/usr/bin/env bash
    

    Don’t you mean instead of the PATCH variable the PATH variable?

    Note: If you export your variable it will be system wide available.

    Login or Signup to reply.
  2. The following is not a proper solution, but anyway, this is a way to run different version of interpreters (bash, python, php…), and make them portable. It will works on other machines of the same architecture only.

    Copy the interpreter binary, in your working folder:

    sudo cp /bin/bash .
    

    Own it and make it executable:

    sudo chmod 777 bash
    

    Test script, calling the interpreter from the current dir:

    #!./bash
    echo "Hello"
    // Output Hello
    

    A better solutions with good documentation can be the tools linuxdeploy and/or appimage, this is using this method under the hood.

    https://github.com/linuxdeploy/linuxdeploy

    https://appimage.org/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search