Solving Unix Script Problem: Finding #s w/ 5 1-4321

  • Thread starter Thread starter Bimpo
  • Start date Start date
  • Tags Tags
    Unix
AI Thread Summary
The discussion focuses on a Unix script problem aimed at counting how many numbers contain the digit '5' between 1 and 4321. The user initially struggles with the correct conditional statement to implement within a while loop. They ultimately resolve the issue by using the syntax `if [[ $current = *[5] ]]`, which checks if the current number includes the digit '5'. The script successfully counts and outputs the total occurrences of numbers containing '5'. The user emphasizes the importance of sharing this solution for future reference.
Bimpo
Messages
9
Reaction score
0

Homework Statement



Trying to find how many numbers contains 5 between 1 to 4321

Homework Equations



n/a

The Attempt at a Solution



#!/bin/bash
typeset -i current=1
typeset -i times=0
while [ $current -le 4321 ] ; do
if [ ] ; then <<<<<<<<<<< stuck here, not sure what to put in if, tried grep etc nonthing works yet
times=times+1
fi
current=current+1
done
echo there are $times numbers that has a 5
 
Physics news on Phys.org
nvm solved it just going to add this for future people whos going to look up this kind of problem in google

if [[ $current = *[5] ]] ; then
 
Back
Top