This is my first time trying to create a bash script and I'm a bit confused.
I'm trying to run my c program from a bash script where the c program can take one or multiple arguments. If the c program takes 1 argument it will print the first n prime numbers depending on what was typed in. If it takes multiple arguments it will print the first n prime numbers of the largest integer argument and then the prime numbers between all possible ranges of the arguments. I'm having issues calling my c program with my bash script. Right now I'm just trying to have it find the largest integer and then print the first n integers:
file=$1
max=$2
shift
for arg in "$@"
do
if [ $arg -gt $max ]; then
max=$arg
fi
done
for file in $path
do
./app "$file" "$max"
done
When I run the bash script if I type:
bash ./prime.sh ./prime 4 3 1
I should get: 2, 3, 5, 7
I did not include the c code because that's currently working.
Thanks!
Get rid of the for
loop, just do:
"$path" "$max"
to run the program in $path
with the argument $max
.
I don't know what ./app
is, but you don't need to run another program to execute a C program.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.