0

I'm planning to create a for loop for this one. But before that, I'm trying to simulate if I can assign a value in a variable that has a variable in it. See below:

x="5"
$myvar${x}=$(ls -lrt FILE_NAME_* | sed -n ${x}p | cut -c47-59)

echo $myvar5

I wanted to assign the filename value in $myvar5 but I don't think I'm using my variables correctly.

Inian
  • 71,145
  • 9
  • 121
  • 139

1 Answers1

1

What you are talking about is called indirection. But this works only for right hand values.

For left hand values you can use declare:

declare myvar$x=foo
ceving
  • 19,833
  • 10
  • 94
  • 150