How to repeat a dash (hyphen) in shell

前端 未结 7 842
北海茫月
北海茫月 2020-12-31 10:10

How can I repeat the character - n times in shell? I have read and tried this, but this does not work for -. It throws error invalid option

7条回答
  •  难免孤独
    2020-12-31 10:40

    Use a for loop and number range:

    for i in {1..10}; 
        do echo "-"; 
    done
    

    Or on a single line:

    for i in {1..10}; 
        do echo -n "-"; 
    done
    

    which outputs ----------.

    EDIT: This was before your printf edit.

提交回复
热议问题