Problem background:
#!/bin/sh
php=100;
Java=101
Language= "PHP JAVA"
For Lang in $LANGUAGE
Todo
What do you want to do with 100, 101 line-by-row output?
Done
Workaround-Numeric string:
#!/bin/sh php=100;
Java=101
Language= "PHP JAVA" for Lang in $LANGUAGE do
Echo $[$lang]
Done
Workaround-Letter string:
#!/bin/sh
Language= (PHP JAVA)
Language_value= (/DATA/1/DATA/2)
For ((i=0;i< ${#LANGUAGE [@]};i++))
Todo
echo ${language_value[$i]}
Done
Shell script Export Environment variables
If you want to use a bash script to export some environment variables to the bash shell, you will encounter some problems. Because each bash script is the only one session, these environment variables will only work in their own scripts, and for the next environment variable to be used, the bash shell does not exist.
For example:
The following statement is included in the env.sh script:
Export Hello=hello
Export Hello2=world
When you're finished running env.sh, then execute echo $HELLO $HELLO 2 in the bash shell, you won't get anything.
The correct way to export an environment variable is to use the source command to export the environment variables from your bash script.
$ source Env.sh
$ echo $HELLO $HELLO 2
$ Hello World
You can put the env.sh script into the/usr/bin directory, then execute source env.sh on any path, and it works well. Here you will use the source command instead of executing the run script directly. But I realize that many users are unaware of the role of the source command.
In the Linux world, there is another way to use these environment variables in a single environment without affecting the use of other shells. It is
Bash-i
Create a new interactive bash session through the Bash script, and exit when you're not using it.
Here is an example:
############################################
build_arm.sh
#!/bin/bash
Export Arch=arm
Export cross_compile=arm-none-linux-gnueabi-
Export ps1= "\e[31mbuild_arm\w\e[m\n\$"
############################################
$ bash-i
Then
$./build_arm.sh
Build_arm ~ $
When you're not using it,
Build_arm ~ $ exit
$
This will exit to the first bash shell.