[英]Linux bash Shell scripting : Creating command using string Append how to do that?
嗨,我想實現#cat sample.txt> abc.txt
但是“> abc.txt”越來越多了。
如何級聯這兩個字符串並執行合並的字符串。
/home/root# export str=" > abc.txt;"
/home/root# echo $str
> abc.txt;
/home/root# echo "cat sample.txt $str"
cat sample.txt > abc.txt;
/home/root# `echo "cat sample.txt $str"`
Hello world
cat: can't open '>': No such file or directory
cat: can't open 'abc.txt;': No such file or directory
像這樣?
#!/bin/bash
args="> foo"
command="date"
eval "$command $args"
cat foo
實際上,不建議使用eval方法,但有時可以用它方便快捷地處理問題。 我可能會因為建議這個而被貶低。 注意它的副作用。
如果您需要從命令行執行此操作,請輸入:
cat sample.txt | tee $str
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.