Bash script - unix - command not found

dside

I am new to bash script and I wonder why I recieve the above message. I try to an arithmetic value which comes from the for loop and then I would like to print the array. Can anyone help me?

Thank you in advance!!

#!/bin/bash
declare -a SCORES
for j in `seq 0 5`;
do
SCORES$j="$(sh myscript.sh $DSLAM $j | grep "" -c )"
done
for k in "${SCORES[@]}"
do
    echo "message $'\t' $SCORES$k"
done
echo ${#SCORES}

=======

Output

abcd.sh: line 16: SCORES0=3: command not found
abcd.sh: line 16: SCORES1=135: command not found
abcd.sh: line 16: SCORES2=826: command not found
abcd.sh: line 16: SCORES3=107: command not found
abcd.sh: line 16: SCORES4=3: command not found
abcd.sh: line 16: SCORES5=3: command not found
0
anishsane

You cannot assign variable with name, which is generated at run time; at least not the way you are trying.

You have below options:

declare "SCORES$j=$(sh myscript.sh $DSLAM $j | grep '' -c )" # creates new variables like SCORES1, SCORES2 etc.

eval "SCORES$j=$(sh myscript.sh $DSLAM $j | grep '' -c )" #Definitely not preferred.

SCORES[$j]="$(sh myscript.sh $DSLAM $j | grep '' -c )" #uses array you have created. 

Most likely, option 3 is what you want.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

command not found in shell script

分類Dev

-bash: cfssl: command not found

分類Dev

Bash alias: command not found

分類Dev

-bash: tsc: command not found

分類Dev

Git bash Command not found

分類Dev

$'\r' - command not found in bash

分類Dev

Shell Script: pacmd: no command found

分類Dev

wget command not found in git bash

分類Dev

Problem with Bash script: 'declare: not found'

分類Dev

Execute sed command in a bash script

分類Dev

Command works in terminal but not in bash script

分類Dev

exit a bash command in a script without exiting the script

分類Dev

Using bash variables in perl command in bash script

分類Dev

Heroku + gunicorn not working (bash: gunicorn: command not found )

分類Dev

pod install -bash: pod: command not found

分類Dev

firebase-tools "-bash:firebase:command not found"

分類Dev

bash_completion causing a 'command not found' in terminal

分類Dev

Calling custom function in bash results in "Command not found"

分類Dev

heroku error bash: gunicorn: command not found

分類Dev

bash command not found when setting a variable

分類Dev

-bash: 400:: command not found when open terminal

分類Dev

command not found assigning value to array in bash

分類Dev

Running a command in a new terminal instance in a bash script

分類Dev

Bash script to monitor file change and execute command

分類Dev

Combine sed commands into one command in bash script

分類Dev

How to execute a command within a bash script?

分類Dev

Linux Bash Script, Single Command But Multiple Lines?

分類Dev

bash: Why are () causing error in script but not on the command line?

分類Dev

Bash script using mysql command with variables failing

Related 関連記事

ホットタグ

アーカイブ