Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k
retitle to describe what you want in proper bash terms
Source Link

Create dynamically strings bash dynamic (variable) variable names

I want to dynamically create a sequence of strings by manipulate an array of elements and create some arithmetic procedure.

for name in FIRST SECOND THIRD FOURTH FIFTH; do
    $name = $(( $6 + 1 ))
    $name = "${$name}q;d"
    echo "${$name}"; printf "\n"
done

The desire outcome would be the below for $6 equals 0.

1q;d
2q;d
3q;d
4q;d
5q;d

But I get this error

/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution

I guess it's something simple. It used to work when I did something like

FIRST=$(( $6 + 1 ))
FIRST="${FIRST}q;d"

Create dynamically strings

I want to dynamically create a sequence of strings by manipulate an array of elements and create some arithmetic procedure.

for name in FIRST SECOND THIRD FOURTH FIFTH; do
    $name = $(( $6 + 1 ))
    $name = "${$name}q;d"
    echo "${$name}"; printf "\n"
done

The desire outcome would be the below for $6 equals 0.

1q;d
2q;d
3q;d
4q;d
5q;d

But I get this error

/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution

I guess it's something simple. It used to work when I did something like

FIRST=$(( $6 + 1 ))
FIRST="${FIRST}q;d"

bash dynamic (variable) variable names

I want to dynamically create a sequence of strings by manipulate an array of elements and create some arithmetic procedure.

for name in FIRST SECOND THIRD FOURTH FIFTH; do
    $name = $(( $6 + 1 ))
    $name = "${$name}q;d"
    echo "${$name}"; printf "\n"
done

The desire outcome would be the below for $6 equals 0.

1q;d
2q;d
3q;d
4q;d
5q;d

But I get this error

reel_first_part.sh: line 18: FIRST: command not found
reel_first_part.sh: line 19: ${$name}q;d: bad substitution
reel_first_part.sh: line 18: FIRST: command not found
reel_first_part.sh: line 19: ${$name}q;d: bad substitution
reel_first_part.sh: line 18: FIRST: command not found
reel_first_part.sh: line 19: ${$name}q;d: bad substitution

I guess it's something simple. It used to work when I did something like

FIRST=$(( $6 + 1 ))
FIRST="${FIRST}q;d"
added 31 characters in body
Source Link

I want to dynamically create a sequence of strings by manipulate an array of elements and create some arithmetic procedure.

for name in FIRST SECOND THIRD FOURTH FIFTH; do
    $name = $(( $6 + 1 ))
    $name = "${$name}q;d"
    echo "${$name}"; printf "\n"
done

The desire outcome would be the below for $6 equals 0.

1q;d
2q;d
3q;d
4q;d
5q;d

But I get this error

/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution

I guess it's something simple. It used to work when I did something like

FIRST=$(( $6 + 1 ))
FIRST="${FIRST}q;d"

I want to dynamically create a sequence of strings by manipulate an array of elements and create some arithmetic procedure.

for name in FIRST SECOND THIRD FOURTH FIFTH; do
    $name = $(( $6 + 1 ))
    $name = "${$name}q;d"
    echo "${$name}"; printf "\n"
done

The desire outcome would be

1q;d
2q;d
3q;d
4q;d
5q;d

But I get this error

/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution

I guess it's something simple. It used to work when I did something like

FIRST=$(( $6 + 1 ))
FIRST="${FIRST}q;d"

I want to dynamically create a sequence of strings by manipulate an array of elements and create some arithmetic procedure.

for name in FIRST SECOND THIRD FOURTH FIFTH; do
    $name = $(( $6 + 1 ))
    $name = "${$name}q;d"
    echo "${$name}"; printf "\n"
done

The desire outcome would be the below for $6 equals 0.

1q;d
2q;d
3q;d
4q;d
5q;d

But I get this error

/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 18: FIRST: command not found
/home/ichristo/Documents/GamesTeam/scripts/reel_first_part.sh: line 19: ${$name}q;d: bad substitution

I guess it's something simple. It used to work when I did something like

FIRST=$(( $6 + 1 ))
FIRST="${FIRST}q;d"
Post Undeleted by giannis christofakis
Post Deleted by giannis christofakis
Post Undeleted by giannis christofakis
Post Deleted by giannis christofakis
Source Link
Loading