#! /usr/bin/bash
for var in "$@"
do
echo $var
done
simple shell script which displays each of the command line arguments, one at a time and stops displaying command line arguments when it gets an argument whose value is “stop”.?
CodePudding user response:
Process args with a while loop:
#!/usr/bin/env bash
while test -n "$1"; do
test "$1" != 'stop' && echo "$1" && shift || break
done
CodePudding user response:
IIUC, try this:
#!/bin/bash
for var in "$@"
do
if [[ "$var" == 'stop' ]]; then
exit 0
else
echo "$var"
fi
done
CodePudding user response:
#!/usr/bin/env bash
fn_EXE(){
VARIABLE=$(echo $@)
for var in $VARIABLE;do
if [[ "$var" == "STOP" ]]; then
echo "encontre el stop=$var Adios !!"
break
else
echo $var
fi
done
}
fn_EXE "A" "B" "C" "D" "E" "STOP" "F"
Saldría del bucle al encontrar un stop en la lista de argumentos..