1

Can someone solve my headache with the following code. I want to write a bash script that will create a table that contain interval of time according to informations input by a user and display table. this is a part of another program but I got stack with this until command that is supposed to be easy to use. Sorry! I'm coding in French but the idea is as I explained

#!/bin/bash
read -p "entrez l'heure de depart(exple: hh:mn:06 or hh:mn:36):" beg_time
read -p "entrez l'intervalle de temps en minute(exple: 10):" Inter
read -p "entrez le nombre d'occurence(exple: 4):" Nbre
let "i = 1"
let "Nb = $Nbre"
tab=("$beg_time")
until [ "$i" -eq "$Nb" ]
do
    tab["$i"]=`date -j -v '+"$Inter"M' -f "%H:%M:%S" "$beg_time" "+%T"`
    let "i += 1"
done
echo ${tab[*]}

but I'm get this as error line 8: until [ 1: command not found I need to mention that I'm using a MacOS so the date command may not work on other linux OS. Please help

Elynho
  • 21
  • 2
  • 4
    It's weird that it seems to be considering `until [ 1` as a single command, makes me think those spaces aren't spaces (nor characters of IFS), maybe unbreakable spaces. That happens especially when you copy/paste from some websites or M$ software. I'd use `cat -A yourscript.sh` to check for them. Here's an example of what I mean : https://ideone.com/lg3vxl, the `M-BM- ` is the unbreakable space in caret-notation – Aaron Aug 06 '20 at 15:45

3 Answers3

1

I find the problem with until. for some reasons I needed to add a space after ]. then I also needed to do some small changes to my script. the final update is as following.

#!/bin/sh
read -p "entrez l'heure de depart(exple: hh:mn:06 or hh:mn:36):" beg_time
read -p "entrez l'intervalle de temps en minute(exple: 10):" Inter
read -p "entrez le nombre d'occurence(exple: 4):" Nbre

let "i = 1"
let "Nb = $Nbre"
tab=("$beg_time")
until [ $Nb -eq $i ] 
do
    tab["$i"]=`date -j -v ""+$Inter"M" -f "%H:%M:%S" "$beg_time" "+%T"`
    beg_time=${tab["$i"]}
    let "i += 1"    
done
echo ${tab[*]}

thank you for helping

Elynho
  • 21
  • 2
  • 4
    You can delete the space and see that it doesn't matter. The more likely reason is that you retyped the line and therefore happened to replace the Unicode formatting spaces with regular ascii spaces as suggested by Aaron in their comment – that other guy Aug 06 '20 at 17:17
0

fix the variable assignments:

i=1
Nb="${Nbre}"

the same goes for let "i += 1"

vgersh99
  • 877
  • 1
  • 5
  • 9
0

Launching this on my mac I don't have the same error :

+"$Inter"M: Cannot apply date adjustment

I think you don't need to quote in your until statement, it's two numbers. Are you using bash or zsh ?

Funkynene
  • 63
  • 8