Skip to main content
Copy edit
Source Link
Benjamin W.
  • 50.1k
  • 19
  • 122
  • 124

BASH Bash array with spaces in elements

I'm trying to construct an Arrayarray in bash-shell of the filenames from my camera:

FILES=(2011-09-04 21.43.02.jpg
2011-09-05 10.23.14.jpg
2011-09-09 12.31.16.jpg
2011-09-11 08.43.12.jpg)

As you can see, there is a space in the middle of each filename.
I've

I've tried wrapping each name in quotes, and escaping the space with a backslash, neither of which works.

 

When I try to access the array elements, it continues to treat the space as the element-delimiterelementdelimiter.

How can I properly capture the filenames with a space inside the name?

BASH array with spaces in elements

I'm trying to construct an Array in bash-shell of the filenames from my camera:

FILES=(2011-09-04 21.43.02.jpg
2011-09-05 10.23.14.jpg
2011-09-09 12.31.16.jpg
2011-09-11 08.43.12.jpg)

As you can see, there is a space in the middle of each filename.
I've tried wrapping each name in quotes, and escaping the space with a backslash, neither of which works.

 

When I try to access the array elements, it continues to treat the space as the element-delimiter.

How can I properly capture the filenames with a space inside the name?

Bash array with spaces in elements

I'm trying to construct an array in bash of the filenames from my camera:

FILES=(2011-09-04 21.43.02.jpg
2011-09-05 10.23.14.jpg
2011-09-09 12.31.16.jpg
2011-09-11 08.43.12.jpg)

As you can see, there is a space in the middle of each filename.

I've tried wrapping each name in quotes, and escaping the space with a backslash, neither of which works.

When I try to access the array elements, it continues to treat the space as the elementdelimiter.

How can I properly capture the filenames with a space inside the name?

added 5 characters in body
Source Link
abelenky
  • 64.4k
  • 23
  • 111
  • 160

I'm trying to construct an Array in bash-shell of the filenames from my camera:

FILES=(2011-09-04 21.43.02.jpg
2011-09-05 10.23.14.jpg
2011-09-09 12.31.16.jpg
2011-09-11 08.43.12.jpg)

As you can see, there is a space in the middle of each filename.
I've tried wrapping each name in quotes, and escaping the space with a backslash, neither of which works. When

When

I try to access the array elements, it continues to treat the space as the element-delimiter.

How can I properly capture the filenames with a space inside the name?

I'm trying to construct an Array in bash-shell of the filenames from my camera:

FILES=(2011-09-04 21.43.02.jpg
2011-09-05 10.23.14.jpg
2011-09-09 12.31.16.jpg
2011-09-11 08.43.12.jpg)

As you can see, there is a space in the middle of each filename.
I've tried wrapping each name in quotes, and escaping the space with a backslash, neither of which works. When I try to access the array elements, it continues to treat the space as the element-delimiter.

How can I properly capture the filenames with a space inside the name?

I'm trying to construct an Array in bash-shell of the filenames from my camera:

FILES=(2011-09-04 21.43.02.jpg
2011-09-05 10.23.14.jpg
2011-09-09 12.31.16.jpg
2011-09-11 08.43.12.jpg)

As you can see, there is a space in the middle of each filename.
I've tried wrapping each name in quotes, and escaping the space with a backslash, neither of which works.

When

I try to access the array elements, it continues to treat the space as the element-delimiter.

How can I properly capture the filenames with a space inside the name?

Source Link
abelenky
  • 64.4k
  • 23
  • 111
  • 160

BASH array with spaces in elements

I'm trying to construct an Array in bash-shell of the filenames from my camera:

FILES=(2011-09-04 21.43.02.jpg
2011-09-05 10.23.14.jpg
2011-09-09 12.31.16.jpg
2011-09-11 08.43.12.jpg)

As you can see, there is a space in the middle of each filename.
I've tried wrapping each name in quotes, and escaping the space with a backslash, neither of which works. When I try to access the array elements, it continues to treat the space as the element-delimiter.

How can I properly capture the filenames with a space inside the name?