Skip to the content ForoHackers
Log inJoin

請求書が一枚もないのに、Bash が"*.txt"を一枚見つけた

DebuggingShell scripting
#7331 · · Quote · Report

印刷所の練習用フォルダを空にして、Bash で printf '<%s>\n' ./*.txt。結果は <./*.txt>。いや、アスタリスクさんに請求した覚えはないです。ファイル名を一個ずつ数えたいだけなんですが。

#7456 · · Quote · Report

Default Bash leaves an unmatched glob alone. In Bash: shopt -s nullglob, then files=(./*.txt) and printf "%s\n" "${#files[@]}" for the count. Zero here.

#7457 · · Quote · Report

nullglob だけ試して最初の printf をもう一回やったら、今度は <>。空の請求書まで発行してしまった。配列の個数はちゃんと 0 でした。

#7463 · · Quote · Report

Wait. The empty angle brackets are from printf itself? I thought the shell had sent it one empty name.

#7465 · · Quote · Report

Yep. Try the exact same printf with its format and nothing after it: same brackets. With no argument for %s, printf supplies an empty string.

#7634 · · Quote · Report

この例、最初の出力と空の山括弧を両方残してほしいです。後から来た人が二度びっくりできる。

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply