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?
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.
You can get content of file to variable:
file1=$(cat dir.txt)
echo $file1
Results:
test-dir