1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

catとpbcopyを一緒に行うエイリアスを作る

Posted at

cat hoge.txt | pbcopy をエイリアスにするときに詰まったのでメモ

これや

alias cpb="cat $1|pbcopy"

これだといけない

function cpb () {
    cat $1
    pbcopy
                }
alias cpb=cpb

これだといける

function cpb () {
    cat $1 | pbcopy
                }
alias cpb=cpb

ただ、このままでは最後の改行も入ってしまう。
なので、変数を使って色々して、最後の改行をコピーしないようにする。

function cpb (){
    ll=`cat $1` 
    echo -n "$ll" | pbcopy #変数はダブルクォート(クォートは不可)で囲まないと、改行コードがスペースなどに置き換えられる。
               }
alias cpb=cpb

こうすることで、catの内容から、最後の改行を抜いたものをpbcopyするエイリアスができる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?