Skip to main content
missing quotes. Added -e to handle values of $command starting with `-`
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

I managed to reproduce the problem. It's a bash escaping problem in the two functions. Try this:

generate_exclude_extensions() {
  echo '(cpp$'
}

generate_exclude_dirs() {
  echo '|^test)'
}

command=$(generate_exclude_extensions)$(generate_exclude_dirs)
echo $command"$command"
git ls-files | grep -vEvEe $command"$command"

my code to reproduce

generate_exclude_extensions() {
  echo '(cpp$'
}

generate_exclude_dirs() {
  echo '|^test)'
}

command=$(generate_exclude_extensions)$(generate_exclude_dirs)
echo $command"$command"
echo -e 'cpp\n
test\n
test456\n
display?5\n' | grep -vEvEe $command"$command"

There are also two typos in your script

generate_exclude_dir -> generate_exclude_dirs
generate_exclud_extensions -> generate_exclude_extensions

:) have fun

I managed to reproduce the problem. It's a bash escaping problem in the two functions. Try this:

generate_exclude_extensions() {
  echo '(cpp$'
}

generate_exclude_dirs() {
  echo '|^test)'
}

command=$(generate_exclude_extensions)$(generate_exclude_dirs)
echo $command
git ls-files | grep -vE $command

my code to reproduce

generate_exclude_extensions() {
  echo '(cpp$'
}

generate_exclude_dirs() {
  echo '|^test)'
}

command=$(generate_exclude_extensions)$(generate_exclude_dirs)
echo $command
echo -e 'cpp\n
test\n
test456\n
display?5\n' | grep -vE $command

There are also two typos in your script

generate_exclude_dir -> generate_exclude_dirs
generate_exclud_extensions -> generate_exclude_extensions

:) have fun

I managed to reproduce the problem. It's a bash escaping problem in the two functions. Try this:

generate_exclude_extensions() {
  echo '(cpp$'
}

generate_exclude_dirs() {
  echo '|^test)'
}

command=$(generate_exclude_extensions)$(generate_exclude_dirs)
echo "$command"
git ls-files | grep -vEe "$command"

my code to reproduce

generate_exclude_extensions() {
  echo '(cpp$'
}

generate_exclude_dirs() {
  echo '|^test)'
}

command=$(generate_exclude_extensions)$(generate_exclude_dirs)
echo "$command"
echo -e 'cpp\n
test\n
test456\n
display?5\n' | grep -vEe "$command"

There are also two typos in your script

generate_exclude_dir -> generate_exclude_dirs
generate_exclud_extensions -> generate_exclude_extensions

:) have fun

Source Link

I managed to reproduce the problem. It's a bash escaping problem in the two functions. Try this:

generate_exclude_extensions() {
  echo '(cpp$'
}

generate_exclude_dirs() {
  echo '|^test)'
}

command=$(generate_exclude_extensions)$(generate_exclude_dirs)
echo $command
git ls-files | grep -vE $command

my code to reproduce

generate_exclude_extensions() {
  echo '(cpp$'
}

generate_exclude_dirs() {
  echo '|^test)'
}

command=$(generate_exclude_extensions)$(generate_exclude_dirs)
echo $command
echo -e 'cpp\n
test\n
test456\n
display?5\n' | grep -vE $command

There are also two typos in your script

generate_exclude_dir -> generate_exclude_dirs
generate_exclud_extensions -> generate_exclude_extensions

:) have fun