ฉันจะแสดงรายการคำสั่ง shell builtin ที่มีอยู่ทั้งหมดได้อย่างไร


23

เรารู้ว่า bash รองรับจำนวน คำสั่ง buitin เช่น:

$ type type cd help command
type is a shell builtin
cd is a shell builtin
help is a shell builtin
command is a shell builtin

ฉันต้องการที่จะได้รับรายชื่อของทุกคำสั่ง builtin เปลือกใช้ได้ ฉันจะทำเช่นนั้นโดยบรรทัดคำสั่งได้อย่างไร



ที่เกี่ยวข้อง (สำหรับคำหลักแทนที่จะเป็นบิวอิน): จะแสดงรายการคำค้นหาเชลล์ทั้งหมดได้อย่างไร
Eliah Kagan

คำตอบ:




13

หรือคุณสามารถแสดงพร้อมenableคำสั่ง: (ทั้งคำตอบของ @ karel's และ @ steeldriver ก็ใช้ได้ดี)

enable -a | cut -d " " -f 2,3

หากมีการปิดการใช้งานบิว-nอิน

ตัวอย่างผลลัพธ์:

$ enable -a | cut -d " " -f 2,3
.
:
[
alias
bg
bind
break
builtin
caller
cd
command
compgen
complete
compopt
continue
declare
dirs
disown
echo
enable
eval
exec
exit
export
false
fc
fg
getopts
hash
help
history
jobs
kill
let
local
logout
mapfile
popd
printf
pushd
pwd
read
readarray
readonly
return
set
shift
shopt
source
suspend
test
times
trap
true
type
typeset
ulimit
umask
unalias
unset
wait

1

สำหรับผู้ที่เกลียดการฟอเร็กซ์ไบนารีภายนอกเพียงสำหรับการจัดรูปแบบ / การแยกข้อมูล:

while read -r _ cmd ; do echo $cmd ; done < <(enable -a)

เหตุใดจึงไม่ใช่เพียงไพพ์แทนการเปลี่ยนเส้นทาง FIFO enable -a | while read ...
David Foerster

นั่นก็จะใช้ได้เช่นกัน นี่เป็นเพียงนิสัยที่ฉันทำเพื่อให้การปรับเปลี่ยนตัวแปรใด ๆ ที่ฉันสนใจที่จะทำในขณะที่ลูปไม่ถูกดำเนินการภายใน sub-shell (การจัดการตัวแปรภายใน sub-shell จะหมายความว่าการเปลี่ยนแปลงจะไม่ถูกเก็บไว้นอกส่วนอื่น ๆ ของลูป)
Nicola Worthington

1

เพียงพิมพ์เทอร์มินัล:

man bash

นี่จะเป็นการเปิดคู่มือการทุบตี เลื่อนลงมาคุณจะพบคำสั่งของเปลือกอาคาร ที่นี่คุณสามารถรู้เกี่ยวกับคำสั่ง builtin ทั้งหมดและสิ่งที่พวกเขาทำ หากคุณต้องการคู่มือในรูปแบบ txt ให้ใช้คำสั่งนี้

man bash > FILENAME.txt

ตอนนี้คุณมีไฟล์ข้อความของคู่มือทุบตี


1

อีกทางหนึ่ง: man builtins

มันจะแสดงรายการของ builtins ที่ด้านบนจากนั้นมีรายละเอียดทั้งหมดสำหรับแต่ละคำสั่งด้านล่าง

SYNOPSIS
       bash defines the following built-in commands: :, ., [, alias, bg, bind,
       break,  builtin,  case,  cd,  command,  compgen,  complete,   continue,
       declare,  dirs, disown, echo, enable, eval, exec, exit, export, fc, fg,
       getopts, hash, help, history, if, jobs, kill, let, local, logout, popd,
       printf,  pushd, pwd, read, readonly, return, set, shift, shopt, source,
       suspend, test, times, trap,  type,  typeset,  ulimit,  umask,  unalias,
       unset, until, wait, while.
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.