Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
リダイレクト文字を含む bash 行 (コマンド) を実行するにはどうすればよいですか? たとえば、次の行は実行できません。
home>CMD="ls -l > out" home>$CMD ls: cannot access >: No such file or directory ls: cannot access out: No such file or directory
事前にご協力いただきありがとうございます。
eval を使用できますが、お勧めしません。コマンドを変数に格納する目的が複数回実行することである場合は、関数を使用することをお勧めします。
例:
dols() { ls -l > out } dols
参照:コマンドを変数に入れようとしていますが、複雑なケースは常に失敗します!
eval $CMDあなたが望むことをします。
eval $CMD