I have a particular string loaded into a variable (v1). I want to define a new variable equal to this variable MINUS the new line and carriage returns so thus I need to delete the new line and carriage returns from this string assigning my new variable.
Here's an example of what I'm trying to do (--> means the terminal output):
v1="Hello\nThere"
v2= $(echo $v1 | tr -d '/n') #This yields the error below.
--> bash: Hello\nThere: No such file or directory
Likewise, if I try to replace say the "l" instead of the '/n', I get:
v2= $(echo $v1 | tr -d l)
--> bash: Heo\nThere: No such file or directory
Notice the "l" disappears on the second example, but this "No such file or directory" pops up which I have no idea what it's signifying. What does this indicate in this context? What file or directory is it looking for? I am just piping the results from echo into tr. I'm not sure what it's referring to when it's talking about No such file or directory.
Moreover, it works if I just do it like so without assigning a new variable
echo $v1 | tr -d l
--> Heo\nThere
Am I assigning the new variable correctly here? I am using the format VariableName= $(expression)
\\ndidn't give the error. When running your command with/n, the output isHello\Therewhich isn't what you want. – Nasir Riley Jun 16 '21 at 23:16