Skip to main content
added 163 characters in body
Source Link
john
  • 303
  • 1
  • 2
  • 9

TL;DR I was writing a very simple bash script, which goes into each folder in my pwd and find for files with names pid. If yes, echo that file out.

pids=$(cat */*/bin/*pid) echo $pids >> 3742031 3741375 3741415 3742159 

The PIDs are nicely printed with spaces

I changed this code a bit to find PIDs in path:

pids=$(cat */*pid) echo $pids >> 37410543741078 

Notice this time it was printed without spaces. Now all these files are auto generated by an application, so the way of storing these values must be consistent - with or without \n etc.

My question is with almost the same code, why in one case it concatenates the string with space and in the other case without space, how is it possible to get a more consistent behavior with cat? (not echo).

Adding the workaround:

Regardless of the file, I am appending a whitespace, before reading the file like: sed '$s/$/ /' */pid. This resolves the problem.

TL;DR I was writing a very simple bash script, which goes into each folder in my pwd and find for files with names pid. If yes, echo that file out.

pids=$(cat */*/bin/*pid) echo $pids >> 3742031 3741375 3741415 3742159 

The PIDs are nicely printed with spaces

I changed this code a bit to find PIDs in path:

pids=$(cat */*pid) echo $pids >> 37410543741078 

Notice this time it was printed without spaces. Now all these files are auto generated by an application, so the way of storing these values must be consistent - with or without \n etc.

My question is with almost the same code, why in one case it concatenates the string with space and in the other case without space, how is it possible to get a more consistent behavior with cat? (not echo).

TL;DR I was writing a very simple bash script, which goes into each folder in my pwd and find for files with names pid. If yes, echo that file out.

pids=$(cat */*/bin/*pid) echo $pids >> 3742031 3741375 3741415 3742159 

The PIDs are nicely printed with spaces

I changed this code a bit to find PIDs in path:

pids=$(cat */*pid) echo $pids >> 37410543741078 

Notice this time it was printed without spaces. Now all these files are auto generated by an application, so the way of storing these values must be consistent - with or without \n etc.

My question is with almost the same code, why in one case it concatenates the string with space and in the other case without space, how is it possible to get a more consistent behavior with cat? (not echo).

Adding the workaround:

Regardless of the file, I am appending a whitespace, before reading the file like: sed '$s/$/ /' */pid. This resolves the problem.

Added tag. Fixed typo.
Source Link
Paulo Tomé
  • 3.9k
  • 6
  • 29
  • 40

TL;DR I was writing a very simple bash script, which goes into each folder in my pwd and find for files with names pid. If yes, echo that file out.

pids=$(cat */*/bin/*pid) echo $pids >> 3742031 3741375 3741415 3742159 

The PIDs are nicely printed with spaces

I changed this code a bit to find PIDs in path:

pids=$(cat */*pid) echo $pids >> 37410543741078 

Notice this time it was printed without spaces. Now all these files are auto generated by an application, so the way of storing these values must be consitentconsistent - with or without \n etc.

My question is with almost the same code, why in one case it concatenates the string with space and in the other case without space, how is it possible to get a more consistent behavior with cat? (not echo)

Thanks.

TL;DR I was writing a very simple bash script, which goes into each folder in my pwd and find for files with names pid. If yes, echo that file out.

pids=$(cat */*/bin/*pid) echo $pids >> 3742031 3741375 3741415 3742159 

The PIDs are nicely printed with spaces

I changed this code a bit to find PIDs in path:

pids=$(cat */*pid) echo $pids >> 37410543741078 

Notice this time it was printed without spaces. Now all these files are auto generated by an application, so the way of storing these values must be consitent - with or without \n etc.

My question is with almost the same code, why in one case it concatenates the string with space and in the other case without space, how is it possible to get a more consistent behavior with cat? (not echo)

Thanks

TL;DR I was writing a very simple bash script, which goes into each folder in my pwd and find for files with names pid. If yes, echo that file out.

pids=$(cat */*/bin/*pid) echo $pids >> 3742031 3741375 3741415 3742159 

The PIDs are nicely printed with spaces

I changed this code a bit to find PIDs in path:

pids=$(cat */*pid) echo $pids >> 37410543741078 

Notice this time it was printed without spaces. Now all these files are auto generated by an application, so the way of storing these values must be consistent - with or without \n etc.

My question is with almost the same code, why in one case it concatenates the string with space and in the other case without space, how is it possible to get a more consistent behavior with cat? (not echo).

deleted 12 characters in body
Source Link
john
  • 303
  • 1
  • 2
  • 9

TL;DR I was writing a very simple bash script, which recursively goes into each folder in my pwd and find for files with names pid. If yes, echo that file out.

pids=$(cat */*/bin/*pid) echo $pids >> 3742031 3741375 3741415 3742159 

The PIDs are nicely printed with spaces

I changed this code a bit to find PIDs in path:

pids=$(cat */*pid) echo $pids >> 37410543741078 

Notice this time it was printed without spaces. Now all these files are auto generated by an application, so the way of storing these values must be consitent - with or without \n etc.

My question is with almost the same code, why in one case it concatenates the string with space and in the other case without space, how is it possible to get a more consistent behavior with cat? (not echo)

Thanks

TL;DR I was writing a very simple bash script, which recursively goes into each folder in my pwd and find for files with names pid. If yes, echo that file out.

pids=$(cat */*/bin/*pid) echo $pids >> 3742031 3741375 3741415 3742159 

The PIDs are nicely printed with spaces

I changed this code a bit to find PIDs in path:

pids=$(cat */*pid) echo $pids >> 37410543741078 

Notice this time it was printed without spaces. Now all these files are auto generated by an application, so the way of storing these values must be consitent - with or without \n etc.

My question is with almost the same code, why in one case it concatenates the string with space and in the other case without space, how is it possible to get a more consistent behavior with cat? (not echo)

Thanks

TL;DR I was writing a very simple bash script, which goes into each folder in my pwd and find for files with names pid. If yes, echo that file out.

pids=$(cat */*/bin/*pid) echo $pids >> 3742031 3741375 3741415 3742159 

The PIDs are nicely printed with spaces

I changed this code a bit to find PIDs in path:

pids=$(cat */*pid) echo $pids >> 37410543741078 

Notice this time it was printed without spaces. Now all these files are auto generated by an application, so the way of storing these values must be consitent - with or without \n etc.

My question is with almost the same code, why in one case it concatenates the string with space and in the other case without space, how is it possible to get a more consistent behavior with cat? (not echo)

Thanks

Source Link
john
  • 303
  • 1
  • 2
  • 9
Loading