compunawer.blogg.se

Batch batch read file into variable
Batch batch read file into variable





batch batch read file into variable

batch batch read file into variable

That said, if you want to source (read) a bash variable from a different file, the best solution is always to use a subshell so that no conflicts arise between your script and the file that is being read: WORKING_VARIABLE=$(source /path/script.sh echo $FILE_VARIABLE) This question is a bit vague, hence a lot of the bizarre responses in fact, some of the answers on this page do not even address the original question whatsoever. In the above example, you'd split the input file into one with the name (say, name.in) and one with the age (say, age.in), and change the read name and read age lines to name=$(cat name.in) and age=$(cat age.in) respectively.

batch batch read file into variable

You're 26 years old, right?".Īs Radu Rădeanu has already suggested, you could use cat inside your script to read the contents of a file into a avariable - in that case, you need each file to contain only one line, with only the value you want for that specific variable. script.shĪnd it would be equivalent to just running the script and entering the data manually - it would print the line "Hello Tomas. You could run this from the terminal in one of the following two ways: $ cat input.in |. You're $age years old, right?"Īnd the input file (called input.in) Tomas

#Batch batch read file into variable how to

# example of how to use the values now stored in variables $name and $ageĮcho "Hello $name. For example, with the program (called script.sh) #!/bin/bash One alternative way to do this would be to just redirect standard input to your file, where you have all the user input in the order it's expected by the program.







Batch batch read file into variable