I am trying to pass a path, stored in a variable as we found here to a bash script. How should it be done, if I call ./my_program.sh input.txt
with? I tried several configurations, without succes. What do you suggest?
#!/bin/bash
export VAR=/home/me/mydir/file.c
export DIR=${VAR%/*}
a_file_in_the_same_directory_of_the_input=file generated from preprocessing of $1
foo(){
./my_function.x "$DIR/a_file_in_the_same_directory_of_the_input"
}
foo "$DIR/a_file_in_the_same_directory_of_the_input" > "$1_processed"
Namely, I give to my_program.sh
the file input.txt
. Hence, a temporary file is produced: a_file_in_the_same_directory_of_the_input
. It is in the same folder of the input. How can I pass it to foo
, by composing the path of the folder with the name of the newly generated file? That's to be sure that the program will always be able to read the temporary file regardless of the directory it is called from.