0

A couple of questions related to .sh script file for Ubuntu. the following is my script:

#!/bin/sh
source /opt/fslc-x11/2.2.1/environment-setup-armv7at2hf-neon-fslc-linux-gnueabi
echo "./make-image-header.sh psplash-poky.png POKY"
./make-image-header.sh psplash-poky.png POKY
echo "autoreconf -vfi"
autoreconf -vfi
echo "./configure --host=x86_64-linux"
./configure --host=x86_64-linux
echo "make"
make
echo "****************** psplash DONE ****************** "

My questions are:

  1. using every single instruction in linux terminal all is ok: how can set the environment inside a script?
  2. supposing my script is outside the current folder, what's the right way to enter in a folder? I tried "cd" command as in terminal, but it doesn't run.
Samathingamajig
  • 11,839
  • 3
  • 12
  • 34
LittleSaints
  • 391
  • 1
  • 6
  • 19
  • 1
    Title and tag say Bash, shebang says sh. Which is it? – Biffen Oct 12 '22 at 09:15
  • I'm really not sure whether the duplicate anwers the question that you tried to be asking. If not, please [edit] to clarify what exactly you want help with. Generally, only ask one question per question, please. – tripleee Oct 12 '22 at 10:49
  • _A couple of questions _ : Please focus on a single problem only. If you are facing more than one problem, ask separate questions instead. – user1934428 Oct 12 '22 at 10:51
  • _set the environment_ : A variable is placed into the environment (inside a bash) script using the `export` command. – user1934428 Oct 12 '22 at 10:52

2 Answers2

0

When you start your script, a new process is created that only inherits your environment. When it ends, it ends. Your current environment stays as it is.

Instead, you can start your script like this:

. script.sh

The . will evaluate the script in the current environment, so it might be altered.

X T
  • 445
  • 6
  • 22
  • It looks like you’re mixing `.` and `source` in this answer. And `.Script.sh` looks strange. – Biffen Oct 12 '22 at 09:27
0

You can check the current directory you are in with pwd. The current directory you will be in is not the directory of where the .sh file is, but the directory you are in when you start running it.

Inside the bash script you can use cd for changing directory, and check with pwd where you are. I hope this helped.

Nora
  • 11
  • 1