1
I have the script below that prints on the screen the even numbers of 1 until the input argument.
#!/bin/bash
for i in $(seq 1 ($1)); do
if [ $(($i % 2)) -eq 0 ]
then
echo "$i \c"
fi
done
For example, for the execution of the script with argument 10 the script prints the following
2 4 6 8 10
I would like the script to print only up to the input value minus 1. That is, $1-1
which for this case is 9
.
I have tried the following modification without success.
for i in $(seq 1 (( $1 - 1 )) ); do
if [ $(($i % 2)) -eq 0 ]
then
echo "$i \c"
fi
done
To optimize more, you don’t even need to use the
if
, can directly apply the operator&&
(AND_IF), thus:[ $(($i % 2)) -eq 0 ] && echo "$i,\c"
– Rafael Toledo