Skip to main content
added 176 characters in body
Source Link
Inian
  • 13.1k
  • 2
  • 42
  • 55

Quote your variables in bash, not doing them will split your words in the variable to individual tokens and the command that uses that variable will be getting multiple words when it was expected a single string (See Word Splitting in shell)

year=$(stat -c %y "$pathfile" | cut -d '-' -f1)

I suppose your problem is in your variable you are using " along with the \ escape sequence. You need to do either of the one.

pathfile="/path/to/file with spaces"

Quote your variables in bash, not doing them will split your words in the variable to individual tokens and the command that uses that variable will be getting multiple words when it was expected a single string (See Word Splitting in shell)

year=$(stat -c %y "$pathfile" | cut -d '-' -f1)

Quote your variables in bash, not doing them will split your words in the variable to individual tokens and the command that uses that variable will be getting multiple words when it was expected a single string (See Word Splitting in shell)

year=$(stat -c %y "$pathfile" | cut -d '-' -f1)

I suppose your problem is in your variable you are using " along with the \ escape sequence. You need to do either of the one.

pathfile="/path/to/file with spaces"
added 153 characters in body
Source Link
Inian
  • 13.1k
  • 2
  • 42
  • 55

Quote your variables in bash, not doing them will split your words in the variable to individual tokens and the command that uses that variable will be getting multiple words, causing errorneous behavior when it was expected a single string (See Word Splitting in shell)

year=$(stat -c %y "$pathfile" | cut -d '-' -f 1f1)

Quote your variables in bash, not doing them will split your words in the variable to individual words, causing errorneous behavior

year=$(stat -c %y "$pathfile" | cut -d '-' -f 1)

Quote your variables in bash, not doing them will split your words in the variable to individual tokens and the command that uses that variable will be getting multiple words when it was expected a single string (See Word Splitting in shell)

year=$(stat -c %y "$pathfile" | cut -d '-' -f1)
Source Link
Inian
  • 13.1k
  • 2
  • 42
  • 55

Quote your variables in bash, not doing them will split your words in the variable to individual words, causing errorneous behavior

year=$(stat -c %y "$pathfile" | cut -d '-' -f 1)