Help us understand the problem. What is going on with this article?

すぐ忘れるfish script syntax

More than 1 year has passed since last update.

これは備忘録

更新予定:随時

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

コマンド実行結果を元にループ処理する場合

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.
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away