shell script crashes during if statements?

Tinler
for hi in `seq 0 100`
do
    new_val=1
    if `expr $hi % 5` -eq 5
    then
        echo hello
    elif `expr $hi % 5` -eq 6
    then
        echo bye
    elif `expr $hi % 5` -eq 7
    then
        echo whats up
    fi
    echo $new_val
done

Why does this crash? The goal is to check if the loop number module 5 equals 5,6, or 7.

Isaac

The script corrected shall be something like:

#!/bin/sh 

for hi in $(seq 0 100)
do
    if [ "$(expr $hi % 5)" -eq 5 ]
    then
        echo hello
    elif [ "$(expr $hi % 5)" -eq 6 ]
    then
        echo bye
    elif [ "$(expr $hi % 5)" -eq 7 ]
    then
        echo whats up
    fi
    echo "$hi"
done

But that loop will never enter any of the ifs as the remainder of a modulus 5 operation will never be 5, 6 or 7.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Nested If Statements in Shell Script

A expect script with multiple shell statements

Transforming IF statements to FOR or WHILE (Shell Script)

determine shell in script during runtime

Difference between quoting variables in shell script "if" statements?

If, elif and else shell script Linux statements

How to use TWO "for statements" in a shell script?

Unable to run shell script during jenkins build

How to run shell script during Docker run

Autodelete generated files after shell script exits or crashes

How to pass the argument in expect shell script during runtime

Trailing spaces during integer to string conversion in power shell script

How can you modify interactively a shell script during the debugging?

How can I allow a shell script to be paused during execution?

MailboxProcessor crashes during Finalize

How to pass echo statements from an invoked shell script into the parameter of a method in the caller script

Pepper crashes during program run

Program crashes during line of scanf

How to use the file names passed as input to shell script using loop statements?

Are assert statements ignored during runtime?

Assigning values during conditional statements

How to change the shell being used from Dash (or sh) to Bash during script execution?

How to ignore or Pass 'Yes' when The authenticity of host can't be established in Expect Shell script during Automation

Why is mv failing in this (bash) shell script in bash 3.2 during Mac OS recovery mode?

How can I list all processes got executed during a shell-script(or sth. like that) running

Can fish shell handle if statements within if statements?

PHP script crashes on ö/é

Restart a vbs script if it crashes

TheGuardian API - Script crashes