I'm trying to create a filename using command param as such but not sure how to go about doing it. This is what I was trying:
echo "AZ" |xargs date >> $1.txt
I'm trying to create a file named AZ.txt with the date in it.
I'm trying to create a filename using command param as such but not sure how to go about doing it. This is what I was trying:
echo "AZ" |xargs date >> $1.txt
I'm trying to create a file named AZ.txt with the date in it.
If you must use xargs, then you'll have to wrap the rest of it in a shell script to delay execution of the redirection until you have constructed the filename:
echo AZ | xargs sh -c 'date >> "$1".txt' sh
The trailing "sh" is to force the xargs argument "AZ" into $1 instead of $0
If the name of the file comes from some command, you can use command substitution:
date > "$(echo AZ)".txt