-1

Suppose in dir.txt I have the following content:

test-dir

I try to use that as a parameter as follows:

echo dir.txt | cp * $1

I want the above to be the equivalent of:

cp * test-dir

What am I doing wrong?

Mary
  • 1,005
  • 2
  • 18
  • 37

2 Answers2

2

You are giving the string "dir.txt" to a program that does not accept any input by stdin.

You are looking for the following syntax:

cp * "$(<dir.txt)"

$() runs the command inside parenthesis and substitutes its results in its position in the command line. The < is a shorthand to read a file (a cat would also work). The quotes are to avoid problems with spaces.

Poshi
  • 5,332
  • 3
  • 15
  • 32
1

You can get content of file to variable:

file1=$(cat dir.txt)
echo $file1

Results:

test-dir
hamza tuna
  • 1,467
  • 1
  • 12
  • 17