Question : How to cat 2 variables variables

Hello Folks,

I have the following problem.

I have 2 files, but I want to append my file A to file B, but this needs to run as script, becuase file A and B never are the same ( I have an script to pick any file on specific folder base on time stamp), this is what I have

#!/bin/bash

A=`cat /path/to/fileA.txt`
B=`cat /path/to/fileB.txt`

cat $A >> $B

but when I do that, I got this:
$B: ambiguous redirect

also, the name needs to be as the B file, I cannot change that.

thank!

Answer : How to cat 2 variables variables

What you need to do instead is not put escapes in the file pathToB. Rather, put double-quotes around $B. It'd probably be a good idea to put double quotes around $A too, in case that path contained spaces in the future (not shown)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:13:10$ cat pathToB
/home/dunc/tests/ee40/B B
12:13:17$ B=$(cat pathToB)
12:13:22$ echo $B
/home/dunc/tests/ee40/B B
12:13:26$ cat $A >> "$B"
12:13:56$ cat B\ B
BB line 1
BB line 2
AA line 1
AA line 2
Open in New Window Select All
Random Solutions  
 
programming4us programming4us