Skip to main content
added 165 characters in body
Source Link
Stéphane Chazelas
  • 588k
  • 96
  • 1.1k
  • 1.7k

The problem is that user_list is accessed as an array

for a in "${user_list[@]}"

but set as a string:

user_list="$(samba-tool user list | grep -i ${txt} | sort)"

Instead you need

IFS=$'\n'     # split on newline characters
set -o noglob # disable globbing

# assign the users to the array using the split+glob operator
# (implicitly invoked in bash when you leave a command substitution
# unquoted in list context):
user_list=( $(samba-tool user list | grep -ie "${txt}" | sort) )

Or better (though bash-specific):

readarray -t user_list < <(samba-tool user list)

(note that that one would create one empty element for each empty line of the input if any, contrary to the split+glob approach which would discard empty lines).

The problem is that user_list is accessed as an array

for a in "${user_list[@]}"

but set as a string:

user_list="$(samba-tool user list | grep -i ${txt} | sort)"

Instead you need

IFS=$'\n'     # split on newline characters
set -o noglob # disable globbing

# assign the users to the array using the split+glob operator
# (implicitly invoked in bash when you leave a command substitution
# unquoted in list context):
user_list=( $(samba-tool user list | grep -ie "${txt}" | sort) )

Or better (though bash-specific):

readarray -t user_list < <(samba-tool user list)

The problem is that user_list is accessed as an array

for a in "${user_list[@]}"

but set as a string:

user_list="$(samba-tool user list | grep -i ${txt} | sort)"

Instead you need

IFS=$'\n'     # split on newline characters
set -o noglob # disable globbing

# assign the users to the array using the split+glob operator
# (implicitly invoked in bash when you leave a command substitution
# unquoted in list context):
user_list=( $(samba-tool user list | grep -ie "${txt}" | sort) )

Or better (though bash-specific):

readarray -t user_list < <(samba-tool user list)

(note that that one would create one empty element for each empty line of the input if any, contrary to the split+glob approach which would discard empty lines).

added 244 characters in body
Source Link
Stéphane Chazelas
  • 588k
  • 96
  • 1.1k
  • 1.7k

The problem is that user_list istis accessed as an array

for a in "${user_list[@]}"

but set as a string:

user_list="$(samba-tool user list | grep -i ${txt} | sort)"

Instead you need

IFS=$'\n'     # split on newline characters
set -o noglob # disable globbing

# assign the users to the array using the split+glob operator
# (implicitly invoked in bash when you leave a command substitution
# unquoted in list context):
user_list=( $(samba-tool user list | grep -iie "${txt}" | sort) )

Or better (though bash-specific):

readarray -t user_list < <(samba-tool user list)

The problem is that user_list ist accessed as an array

for a in "${user_list[@]}"

but set as a string:

user_list="$(samba-tool user list | grep -i ${txt} | sort)"

Instead you need

user_list=( $(samba-tool user list | grep -i "${txt}" | sort) )

The problem is that user_list is accessed as an array

for a in "${user_list[@]}"

but set as a string:

user_list="$(samba-tool user list | grep -i ${txt} | sort)"

Instead you need

IFS=$'\n'     # split on newline characters
set -o noglob # disable globbing

# assign the users to the array using the split+glob operator
# (implicitly invoked in bash when you leave a command substitution
# unquoted in list context):
user_list=( $(samba-tool user list | grep -ie "${txt}" | sort) )

Or better (though bash-specific):

readarray -t user_list < <(samba-tool user list)
Source Link
Hauke Laging
  • 94.8k
  • 22
  • 133
  • 185

The problem is that user_list ist accessed as an array

for a in "${user_list[@]}"

but set as a string:

user_list="$(samba-tool user list | grep -i ${txt} | sort)"

Instead you need

user_list=( $(samba-tool user list | grep -i "${txt}" | sort) )