Linux command ambiguous redirect

后端 未结 3 1003
再見小時候
再見小時候 2021-01-26 09:58

Hi I have a lab header called header.txt and I want to cat into my 3 C files cat ../header.txt > find -name *.c

What is wrong with the above statement?

3条回答
  •  野性不改
    2021-01-26 10:25

    Output redirection is for files, not commands. You'll need to process each file separately.

    find -name *.c -print0 | while IFS= read -r -d '' f; do
      cat ../header.txt >> $f   # Append instead of overwriting
    done
    

    As for the 'ambiguous redirect', you normally get that when you write something like:

    ... > *.c
    

    and the glob *.c expands to more than one file. For example:

    $ echo "" >> *.c
    -sh: *.c: ambiguous redirect
    $
    

提交回复
热议问题