Skip to main content
added 2 characters in body
Source Link

basename doesn't deal with multiple files:

NAME

basename - strip directory and suffix from filenames   

SYNOPSIS

  basename NAME [SUFFIX]    basename OPTION...NAME...

Unless the -a option is used (GNU Coreutils):

-a, --multiple
   support multiple arguments and treat each as a NAME

But thatit would break if the filenames have newlines.

And will fail in your command, since basename -a will return the arguments with new lines

basename "$@"
foo.pdf
bar.pdf

Which breaks the rm command since the arguments passes are separated by new lines.

This code apparently solves the problem

rm $(echo $"$(basename -a "$@")")

but I'm not so sure of its validity.


Yo can then loop over the arguments:

for i in "$@"; do 
  echo "rm -f /tmp/$(basename "$i")"
  rm -f "/tmp/$(basename "$i")"
done

To deal with names with spaces, they must be properly escaped when passed to the script:

$ script.sh "foo bar.pdf"

Or

$ script.sh foo\ bar.pdf

basename doesn't deal with multiple files:

NAME

basename - strip directory and suffix from filenames   

SYNOPSIS

  basename NAME [SUFFIX]    basename OPTION...NAME...

Unless the -a option is used (GNU Coreutils):

-a, --multiple
   support multiple arguments and treat each as a NAME

But that will fail in your command, since basename -a will return the arguments with new lines

basename "$@"
foo.pdf
bar.pdf

Which breaks the rm command since the arguments passes are separated by new lines.

This code apparently solves the problem

rm $(echo $(basename -a "$@"))

but I'm not so sure of its validity.


Yo can then loop over the arguments:

for i in "$@"; do 
  echo "rm -f /tmp/$(basename "$i")"
  rm -f "/tmp/$(basename "$i")"
done

To deal with names with spaces, they must be properly escaped when passed to the script:

$ script.sh "foo bar.pdf"

Or

$ script.sh foo\ bar.pdf

basename doesn't deal with multiple files:

NAME

basename - strip directory and suffix from filenames   

SYNOPSIS

  basename NAME [SUFFIX]    basename OPTION...NAME...

Unless the -a option is used (GNU Coreutils):

-a, --multiple
   support multiple arguments and treat each as a NAME

But it would break if the filenames have newlines.

And will fail in your command, since basename -a will return the arguments with new lines

basename "$@"
foo.pdf
bar.pdf

Which breaks the rm command since the arguments passes are separated by new lines.

This code apparently solves the problem

rm $(echo "$(basename -a "$@")")

but I'm not so sure of its validity.


Yo can then loop over the arguments:

for i in "$@"; do 
  echo "rm -f /tmp/$(basename "$i")"
  rm -f "/tmp/$(basename "$i")"
done

To deal with names with spaces, they must be properly escaped when passed to the script:

$ script.sh "foo bar.pdf"

Or

$ script.sh foo\ bar.pdf
added 65 characters in body
Source Link

basename doesn't deal with multiple files:

NAME

basename - strip directory and suffix from filenames   

SYNOPSIS

  basename NAME [SUFFIX]    basename OPTION...NAME...

Unless the -a option is used (GNU Coreutils):

-a, --multiple
   support multiple arguments and treat each as a NAME

But that will fail in your command, since basename -a would break ifwill return the filenames have newlinesarguments with new lines

basename "$@"
foo.pdf
bar.pdf

Which breaks the rm command since the arguments passes are separated by new lines.

This code apparently solves the problem

rm $(echo $(basename -a "$@"))

but I'm not so sure of its validity.


Yo can then loop over the arguments:

for i in "$@"; do 
  echo "rm -f /tmp/$(basename "$i")"
  rm -f "/tmp/$(basename "$i")"
done

To deal with names with spaces, they must be properly escaped when passed to the script:

$ script.sh "foo bar.pdf"

Or

$ script.sh foo\ bar.pdf

basename doesn't deal with multiple files:

NAME

basename - strip directory and suffix from filenames   

SYNOPSIS

  basename NAME [SUFFIX]    basename OPTION...NAME...

Unless the -a option is used (GNU Coreutils):

-a, --multiple
   support multiple arguments and treat each as a NAME

But that will fail in your command, since basename -a would break if the filenames have newlines.


Yo can then loop over the arguments:

for i in "$@"; do 
  echo "rm -f /tmp/$(basename "$i")"
  rm -f "/tmp/$(basename "$i")"
done

To deal with names with spaces, they must be properly escaped when passed to the script:

$ script.sh "foo bar.pdf"

Or

$ script.sh foo\ bar.pdf

basename doesn't deal with multiple files:

NAME

basename - strip directory and suffix from filenames   

SYNOPSIS

  basename NAME [SUFFIX]    basename OPTION...NAME...

Unless the -a option is used (GNU Coreutils):

-a, --multiple
   support multiple arguments and treat each as a NAME

But that will fail in your command, since basename -a will return the arguments with new lines

basename "$@"
foo.pdf
bar.pdf

Which breaks the rm command since the arguments passes are separated by new lines.

This code apparently solves the problem

rm $(echo $(basename -a "$@"))

but I'm not so sure of its validity.


Yo can then loop over the arguments:

for i in "$@"; do 
  echo "rm -f /tmp/$(basename "$i")"
  rm -f "/tmp/$(basename "$i")"
done

To deal with names with spaces, they must be properly escaped when passed to the script:

$ script.sh "foo bar.pdf"

Or

$ script.sh foo\ bar.pdf
added 65 characters in body
Source Link

basename doesn't deal with multiple files:

NAME

basename - strip directory and suffix from filenames   

SYNOPSIS

  basename NAME [SUFFIX]    basename OPTION...NAME...

Unless the -a option is used (GNU Coreutils):

-a, --multiple
   support multiple arguments and treat each as a NAME

But that will fail in your command, since basename -a would break if the filenames have newlines.


Yo can then loop over the arguments:

for i in "$@"; do 
  echo "rm -f /tmp/$(basename "$i")"
  rm -f "/tmp/$(basename "$i")"
done

To deal with names with spaces, they must be properly escaped when passed to the script:

$ script.sh "foo bar.pdf"

Or

$ script.sh foo\ bar.pdf

basename doesn't deal with multiple files:

NAME

basename - strip directory and suffix from filenames   

SYNOPSIS

  basename NAME [SUFFIX]    basename OPTION...NAME...

Unless the -a option is used (GNU Coreutils):

-a, --multiple
   support multiple arguments and treat each as a NAME

But that will fail in your command.


Yo can then loop over the arguments:

for i in "$@"; do 
  echo "rm -f /tmp/$(basename "$i")"
  rm -f "/tmp/$(basename "$i")"
done

To deal with names with spaces, they must be properly escaped when passed to the script:

$ script.sh "foo bar.pdf"

Or

$ script.sh foo\ bar.pdf

basename doesn't deal with multiple files:

NAME

basename - strip directory and suffix from filenames   

SYNOPSIS

  basename NAME [SUFFIX]    basename OPTION...NAME...

Unless the -a option is used (GNU Coreutils):

-a, --multiple
   support multiple arguments and treat each as a NAME

But that will fail in your command, since basename -a would break if the filenames have newlines.


Yo can then loop over the arguments:

for i in "$@"; do 
  echo "rm -f /tmp/$(basename "$i")"
  rm -f "/tmp/$(basename "$i")"
done

To deal with names with spaces, they must be properly escaped when passed to the script:

$ script.sh "foo bar.pdf"

Or

$ script.sh foo\ bar.pdf
added 127 characters in body
Source Link
Loading
added 190 characters in body
Source Link
Loading
deleted 63 characters in body
Source Link
Loading
quote the expansions
Source Link
ilkkachu
  • 148.2k
  • 16
  • 268
  • 441
Loading
Source Link
Loading