Home
Packages
Forums
Wiki
GitLab
Security
AUR
Download
コンテンツにスキップ
メインメニュー
メインメニュー
サイドバーに移動
非表示
案内
メインページ
目次
コミュニティに貢献
最近の出来事
おまかせ表示
特別ページ
交流
ヘルプ
貢献
最近の更新
最近の議論
新しいページ
統計
リクエスト
ArchWiki
検索
検索
表示
アカウント作成
ログイン
個人用ツール
アカウント作成
ログイン
Nushellのソースを表示
ページ
議論
日本語
閲覧
ソースを閲覧
履歴を表示
ツール
ツール
サイドバーに移動
非表示
操作
閲覧
ソースを閲覧
履歴を表示
全般
リンク元
関連ページの更新状況
ページ情報
表示
サイドバーに移動
非表示
←
Nushell
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
{{Lowercase title}} [[Category:コマンドラインシェル]] [https://www.nushell.sh/ nushell]は、新しいタイプのシェルです。配列、テーブル、レコード、数値/ブール型などの構造化・型付けされたデータをネイティブにサポートし、シェルのようなワークフローで様々なデータ型の問い合わせ、フィルタ、ソート、変換、その他の操作を容易にする構文とビルトインを提供し、多くのビルトインまたはユーザー定義フォーマットでの入力と出力をサポートします。 == インストール == {{Pkg|nushell}} パッケージを[[インストール]]します。 == 機能概要 == === 構造化データのサポート === Built-ins in '''nushell''' understand and output complex data types. For example, the {{ic|ls}} builtin outputs an array of items representing files, which have attributes like {{ic|name}}, {{ic|size}}, {{ic|type}} ({{ic|file}}, {{ic|dir}}, {{ic|symlink}}, etc.), {{ic|modified}}, etc. In addition, many built-ins are offered for querying and manipulating data, as data - not as text like in traditional shell, while still having a shell-like workflow. For example, the {{ic|where}} builtin can filter the contents of an array or table: $ ls | where type == file | where size > 10mb Since it filters data received via its "stdin" and produces it via its "stdout", multiple filters can be chained like above. Another example: $ ls | where type == file | get size | sum The {{ic|get}} builtin can be used access an attribute from an object. In this example, we are feeding it an array of objects via stdin, so it fetches the {{ic|size}} property of each element in the array, which produces an array of numeric values. Finally, we feed that array to {{ic|sum}} which calculates their sum. === 出力 === '''nushell''' has extremely versatile output features. Right out of the box, it boasts a modern look with colors, ASCII art, and detailed error messages. ==== テキストで出力する ==== By default, the output of commands like {{ic|ls}} (which as we said produces an array of structured objects) is displayed as a colorized ASCII table with enumerated rows, where each file is a row and each attribute is a column. Example: /usr/lib> ls | where name =~ ".*(alsa|pulse|pipewire).*" | first 10 ╭───┬────────────────────────────┬─────────┬──────────┬──────────────╮ │ # │ name │ type │ size │ modified │ ├───┼────────────────────────────┼─────────┼──────────┼──────────────┤ │ 0 │ alsa-lib │ dir │ 4.1 KB │ 2 days ago │ │ 1 │ alsa-topology │ dir │ 4.1 KB │ 3 months ago │ │ 2 │ libdrumstick-alsa.so │ symlink │ 22 B │ 7 months ago │ │ 3 │ libdrumstick-alsa.so.2 │ symlink │ 26 B │ 7 months ago │ │ 4 │ libdrumstick-alsa.so.2.7.2 │ file │ 335.3 KB │ 7 months ago │ │ 5 │ libgvncpulse-1.0.so │ symlink │ 21 B │ 9 months ago │ │ 6 │ libgvncpulse-1.0.so.0 │ symlink │ 25 B │ 9 months ago │ │ 7 │ libgvncpulse-1.0.so.0.0.1 │ file │ 14.1 KB │ 9 months ago │ │ 8 │ libpipewire-0.3.so │ symlink │ 20 B │ 2 weeks ago │ │ 9 │ libpipewire-0.3.so.0 │ symlink │ 26 B │ 2 weeks ago │ ╰───┴────────────────────────────┴─────────┴──────────┴──────────────╯ ==== データ形式での出力 ====== Data can also be output in any various data formats, including JSON, YAML, TOML, HTML, XML, SQL, CSV, Markdown tables, and others. The user can also define their own custom viewers to support arbitrary data types. To output data in a given format, simply pipe the data to {{ic|to ''FORMAT''}}: /usr/lib> ls | where name =~ ".*alsa.*" | first 3 | to yaml - name: alsa-lib type: dir size: 4096 modified: 2023-05-03 16:04:35.544273606 - name: alsa-topology type: dir size: 4096 modified: 2023-01-13 19:29:45.179245376 - name: libdrumstick-alsa.so type: symlink size: 22 modified: 2022-10-02 13:28:57 To save the output of a command in a file, pipe it to the {{ic|save}} builtin: > ls | to json | save my-file.json If the output file already exists, {{ic|save}} will refuse to overwrite it. You can force overwriting files using the {{ic|-f}} switch. Note that '''nushell''' defaults to producing pretty-printed JSON. To output JSON without pretty-printing, use {{ic|to json --raw}}. See {{ic|to --help}} for a list of supported formats. ==== エラー出力 ==== '''nushell''' prints colorized and detailed error messages that pinpoint the exact source of the error and suggest solutions. Example error message: > ls -a --never-gonna-give-you-up /tmp Error: nu::parser::unknown_flag × The `ls` command doesn't have flag `never-gonna-give-you-up`. ╭─[entry #24:1:1] 1 │ ls -a --never-gonna-give-you-up /tmp · ────────────┬──────────── · ╰── unknown flag ╰──── help: Available flags: --help(-h), --all(-a), --long(-l), --short-names(-s), --full-paths(-f), --du(-d), --directory(-D), --mime-type(-m). Use `--help` for more information. === 入力 === ==== データファイルからの入力 ==== '''nushell''' has native support for reading data in various formats, including JSON, YAML, TOML, SQL, HTML/XML, and others, allowing the user to utilize its powerful data querying and manipulation capabilities on data read from any file format. The user can also add support for new formats by adding plugins. Data is read from files using the {{ic|open}} builtin. For example, assuming we have a file {{ic|movies.yaml}} with the following contents: - movie: Matrix genre: Action - movie: Lord of the Rings genre: [Action, Fantasy] - movie: Independence Day genre: [Action, Sci-Fi] Then executing {{ic|open movies.yaml}} would produce the following output: ╭───┬───────────────────┬─────────────────╮ │ # │ movie │ genre │ ├───┼───────────────────┼─────────────────┤ │ 0 │ Matrix │ Action │ │ 1 │ Lord of the Rings │ ╭───┬─────────╮ │ │ │ │ │ 0 │ Action │ │ │ │ │ │ 1 │ Fantasy │ │ │ │ │ ╰───┴─────────╯ │ │ 1 │ Independence Day │ ╭───┬─────────╮ │ │ │ │ │ 0 │ Action │ │ │ │ │ │ 1 │ Sci-Fi │ │ │ │ │ ╰───┴─────────╯ │ ╰───┴───────────────────┴─────────────────╯ ==== Input from external programs ==== For external programs, which typically produce their output as plain text, '''nushell''' offers the ability to parse their output and convert it into a structured datatype, so that the user can utilize '''nushell'''<nowiki/>'s full native data processing capabilities even on arbitrary output generated by agnostic programs. ===== Using parse with regular expression ===== Parsing external program output can be easily performed using the {{ic|parse}} builtin. One typical workflow is using the {{ic|-r}} switch, which tells {{ic|parse}} to use a [[Wikipedia:Regular_expression|regular expression]] for extracting fields out of each line of text in the input. For example, to parse the output of [[pacman]]'s {{ic|-Si}} [[pacman#Querying package databases|command]], one might do something like this: > pacman -Si rclone | parse -r '(?P<name>.*\w) +: (?P<value>.+)' ╭────┬────────────────┬─────────────────────────────────────────────────╮ │ # │ name │ value │ ├────┼────────────────┼─────────────────────────────────────────────────┤ │ 0 │ Repository │ extra │ │ 1 │ Name │ rclone │ │ 2 │ Version │ 1.62.2-1 │ │ 3 │ Description │ Sync files to and from Google Drive, S3, Swift, │ │ │ │ Cloudfiles, Dropbox and Google Cloud Storage │ │ 4 │ Architecture │ x86_64 │ │ 5 │ URL │ <nowiki>https://rclone.org/</nowiki> │ │ 6 │ Licenses │ MIT │ │ 7 │ Groups │ None │ │ 8 │ Provides │ None │ │ 9 │ Depends On │ glibc │ │ 10 │ Optional Deps │ fuse2: for rclone mount │ │ 11 │ Conflicts With │ None │ │ 12 │ Replaces │ None │ │ 13 │ Download Size │ 18.12 MiB │ │ 14 │ Installed Size │ 75.93 MiB │ │ 15 │ Packager │ Morten Linderud <foxboron@archlinux.org> │ │ 16 │ Build Date │ Sun 02 Apr 2023 14:09:44 EEST │ │ 17 │ Validated By │ MD5 Sum SHA-256 Sum Signature │ ╰────┴────────────────┴─────────────────────────────────────────────────╯ '''nushell'''<nowiki/> uses a Perl-like regular expression syntax, which is provided by the [https://github.com/rust-lang/regex Regex crate] (of the [[Rust]] programming language). The syntax is described in the [https://docs.rs/regex/latest/regex/#syntax crate's documentation]. ===== Using parse with template string ===== Another way, which does not require regular expression knowledge, is by omitting the {{ic|-r}} switch and providing {{ic|parse}} with a template string. However, depending on the case, it may necessitate extra steps for pre- and post-processsing the results. For example: > pacman -Si just | lines | parse '{field} : {value}' | str trim Here we performed the same task as the above, but with three differences. Aside from using a template string rather than regular expression (i.e. without the {{ic|-r}} switch), the first notable difference is that when {{ic|parse}} is given a a template strings, it acts on the entirety of its input rather than on each line in it. So in order to parse the input on a per-line basis, we must first split it into an array of lines using the {{ic|lines}} builtin. The second difference is that template strings do not automatically trim surplus whitespace, which results in the matched fields containing all extra whitespace surrounding them, so we had to post-process the output with {{ic|str trim}}, which conveniently acts on all fields for all items in the provided array. === Data manipulation === ==== Conversion ==== The combination of its {{ic|open}} and {{ic|save}} builtins allow it to be easily used to convert data files across any supported formats. For example: The data can then be freely manipulated or converted by piping it to other commands. For example: > open movies.yaml | first 2 | to json --raw [{"movie": "Matrix","genre": "Action"},{"movie": "Lord of the Rings","genre":["Action","Fantasy"]}] > open movies.yaml | first 2 | to json --raw | save movies.json > cat movies.json ''(same output as above)'' == Comparison with traditional shells == {{Expansion|Needs to elaborate on some of the points enumerated in the first paragraph.}} '''nushell''' is not a POSIX shell, and has significant differences from traditional/POSIX-compatible shells in various ways, including its syntax, supported builtins, the way builtins work, the command-line options they accept, the type of data they consume and produce, and so on. === Syntax === Redirecting output to a file cannot be done using {{ic|>}} like in other shells. Instead, you must use the {{ic|save}} builtin. If the output in question happens to be a complex data structure (like the output of its builtin {{ic|ls}}), then you must first serialize it into a textual representation using the {{ic|to}} builtin. So rather than: ls > file.txt You must use: ls | to yaml | save file.yaml == See slso == * [https://www.nushell.sh/ '''nushell'''<nowiki/>'s Project Homepage]. * [https://www.nushell.sh/book/ Nushell's Introductory Book], which goes in detail about its features and facets. * [https://www.nushell.sh/commands/ Nushell's Command Reference] * [https://www.nushell.sh/cookbook/ Nushell's Cookbook], containing examples about how to perform tasks from various categories in '''nushell'''.
このページで使用されているテンプレート:
テンプレート:Expansion
(
ソースを閲覧
)
テンプレート:Ic
(
ソースを閲覧
)
テンプレート:Lowercase title
(
ソースを閲覧
)
テンプレート:META Message
(
ソースを閲覧
)
テンプレート:Pkg
(
ソースを閲覧
)
Nushell
に戻る。
検索
検索
Nushellのソースを表示
話題を追加