これは備忘録
更新予定:随時
script arguments
コマンドラインから与えられた引数の値は$argv
配列(indexは1から始まる)を参照することで得られる。
argv, an array of arguments to the shell or function. argv is only defined when inside a function call, or if fish was invoked with a list of arguments, like fish myscript.fish foo bar. This variable can be changed by the user.
"Special variables" / http://fishshell.com/docs/current/index.html
hoge.fish
# !/usr/bin/env
echo $argv[1]
$ ./hoge.fish "fuga"
fuga
loop with command
コマンド実行結果を元にループ処理する場合
- https://fishshell.com/docs/current/commands.html#string
- http://stackoverflow.com/questions/19638400/fish-equivalent-to-for-loop-with-evaluation
loop.fish
# !/usr/bin/env fish
for i in (ls *.mp4)
mv $i (string replace .mp4 .m4a $i)
end
$ ls *.mp4
hoge.mp4
fuga.mp4
bar.mp4
$ ./loop.fish
$ ls *.m4a
hoge.m4a
fuga.m4a
bar.m4a
上記の処理に限っては、Finderだけで一括変換できるが、わかりやすい例として挙げておく。
Operators for files and directories
下記の-e
んとこのスイッチリスト
if test -e /var/path/hoge.log
echo 'available'
end
-b FILE returns true if FILE is a block device.
-c FILE returns true if FILE is a character device.
-d FILE returns true if FILE is a directory.
-e FILE returns true if FILE exists.
-f FILE returns true if FILE is a regular file.
-g FILE returns true if FILE has the set-group-ID bit set.
-G FILE returns true if FILE exists and has the same group ID as the current user.
-L FILE returns true if FILE is a symbolic link.
-O FILE returns true if FILE exists and is owned by the current user.
-p FILE returns true if FILE is a named pipe.
-r FILE returns true if FILE is marked as readable.
-s FILE returns true if the size of FILE is greater than zero.
-S FILE returns true if FILE is a socket.
-t FD returns true if the file descriptor FD is a terminal (TTY).
-u FILE returns true if FILE has the set-user-ID bit set.
-w FILE returns true if FILE is marked as writable; note that this does not check if the filesystem is read-only.
-x FILE returns true if FILE is marked as executable.