head 1.259; access; symbols netbsd-10-0-RELEASE:1.252.2.1 netbsd-10-0-RC6:1.252.2.1 netbsd-10-0-RC5:1.252.2.1 netbsd-10-0-RC4:1.252.2.1 netbsd-10-0-RC3:1.252.2.1 netbsd-10-0-RC2:1.252.2.1 netbsd-10-0-RC1:1.252.2.1 netbsd-10:1.252.0.2 netbsd-10-base:1.252 netbsd-9-3-RELEASE:1.223.2.2 cjep_sun2x-base1:1.229 cjep_sun2x:1.229.0.4 cjep_sun2x-base:1.229 cjep_staticlib_x-base1:1.229 netbsd-9-2-RELEASE:1.223 cjep_staticlib_x:1.229.0.2 cjep_staticlib_x-base:1.229 netbsd-9-1-RELEASE:1.223 phil-wifi-20200421:1.224 phil-wifi-20200411:1.224 is-mlppp:1.224.0.2 is-mlppp-base:1.224 phil-wifi-20200406:1.224 netbsd-8-2-RELEASE:1.146.2.6 netbsd-9-0-RELEASE:1.223 netbsd-9-0-RC2:1.223 netbsd-9-0-RC1:1.223 phil-wifi-20191119:1.223 netbsd-9:1.223.0.2 netbsd-9-base:1.223 phil-wifi-20190609:1.223 netbsd-8-1-RELEASE:1.146.2.6 netbsd-8-1-RC1:1.146.2.6 pgoyette-compat-merge-20190127:1.175.2.7 pgoyette-compat-20190127:1.217 pgoyette-compat-20190118:1.216 pgoyette-compat-1226:1.216 pgoyette-compat-1126:1.209 pgoyette-compat-1020:1.208 pgoyette-compat-0930:1.208 pgoyette-compat-0906:1.208 netbsd-7-2-RELEASE:1.114 pgoyette-compat-0728:1.206 netbsd-8-0-RELEASE:1.146.2.5 phil-wifi:1.206.0.2 phil-wifi-base:1.206 pgoyette-compat-0625:1.206 netbsd-8-0-RC2:1.146.2.5 pgoyette-compat-0521:1.206 pgoyette-compat-0502:1.203 pgoyette-compat-0422:1.203 netbsd-8-0-RC1:1.146.2.5 pgoyette-compat-0415:1.203 pgoyette-compat-0407:1.203 pgoyette-compat-0330:1.203 pgoyette-compat-0322:1.203 pgoyette-compat-0315:1.193 netbsd-7-1-2-RELEASE:1.114 pgoyette-compat:1.175.0.2 pgoyette-compat-base:1.175 netbsd-7-1-1-RELEASE:1.114 matt-nb8-mediatek:1.146.2.5.0.2 matt-nb8-mediatek-base:1.146.2.5 perseant-stdc-iso10646:1.159.0.2 perseant-stdc-iso10646-base:1.159 netbsd-8:1.146.0.2 netbsd-8-base:1.146 prg-localcount2-base3:1.143 prg-localcount2-base2:1.136 prg-localcount2-base1:1.133 prg-localcount2:1.131.0.2 prg-localcount2-base:1.131 pgoyette-localcount-20170426:1.131 bouyer-socketcan-base1:1.131 pgoyette-localcount-20170320:1.125 netbsd-7-1:1.114.0.8 netbsd-7-1-RELEASE:1.114 netbsd-7-1-RC2:1.114 netbsd-7-nhusb-base-20170116:1.114 bouyer-socketcan:1.123.0.4 bouyer-socketcan-base:1.123 pgoyette-localcount-20170107:1.123 netbsd-7-1-RC1:1.114 pgoyette-localcount-20161104:1.123 netbsd-7-0-2-RELEASE:1.114 localcount-20160914:1.123 netbsd-7-nhusb:1.114.0.6 netbsd-7-nhusb-base:1.114 pgoyette-localcount-20160806:1.123 pgoyette-localcount-20160726:1.123 pgoyette-localcount:1.123.0.2 pgoyette-localcount-base:1.123 netbsd-7-0-1-RELEASE:1.114 netbsd-7-0:1.114.0.4 netbsd-7-0-RELEASE:1.114 netbsd-7-0-RC3:1.114 netbsd-7-0-RC2:1.114 netbsd-7-0-RC1:1.114 netbsd-5-2-3-RELEASE:1.87.18.3 netbsd-5-1-5-RELEASE:1.87.18.3 netbsd-6-0-6-RELEASE:1.106 netbsd-6-1-5-RELEASE:1.106 netbsd-7:1.114.0.2 netbsd-7-base:1.114 yamt-pagecache-base9:1.112 yamt-pagecache-tag8:1.106.2.1 netbsd-6-1-4-RELEASE:1.106 netbsd-6-0-5-RELEASE:1.106 tls-earlyentropy:1.112.0.2 tls-earlyentropy-base:1.114 riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.112 riastradh-drm2-base3:1.112 netbsd-6-1-3-RELEASE:1.106 netbsd-6-0-4-RELEASE:1.106 netbsd-5-2-2-RELEASE:1.87.18.3 netbsd-5-1-4-RELEASE:1.87.18.3 netbsd-6-1-2-RELEASE:1.106 netbsd-6-0-3-RELEASE:1.106 netbsd-5-2-1-RELEASE:1.87.18.3 netbsd-5-1-3-RELEASE:1.87.18.3 netbsd-6-1-1-RELEASE:1.106 riastradh-drm2-base2:1.110 riastradh-drm2-base1:1.110 riastradh-drm2:1.110.0.2 riastradh-drm2-base:1.110 netbsd-6-1:1.106.0.10 netbsd-6-0-2-RELEASE:1.106 netbsd-6-1-RELEASE:1.106 khorben-n900:1.109.0.6 netbsd-6-1-RC4:1.106 netbsd-6-1-RC3:1.106 agc-symver:1.109.0.4 agc-symver-base:1.109 netbsd-6-1-RC2:1.106 netbsd-6-1-RC1:1.106 yamt-pagecache-base8:1.109 netbsd-5-2:1.87.18.3.0.6 netbsd-6-0-1-RELEASE:1.106 yamt-pagecache-base7:1.109 netbsd-5-2-RELEASE:1.87.18.3 netbsd-5-2-RC1:1.87.18.3 matt-nb6-plus-nbase:1.106 yamt-pagecache-base6:1.109 netbsd-6-0:1.106.0.8 netbsd-6-0-RELEASE:1.106 netbsd-6-0-RC2:1.106 tls-maxphys:1.108.0.2 tls-maxphys-base:1.114 matt-nb6-plus:1.106.0.6 matt-nb6-plus-base:1.106 netbsd-6-0-RC1:1.106 yamt-pagecache-base5:1.106 yamt-pagecache-base4:1.106 netbsd-6:1.106.0.4 netbsd-6-base:1.106 netbsd-5-1-2-RELEASE:1.87.18.3 netbsd-5-1-1-RELEASE:1.87.18.3 yamt-pagecache-base3:1.106 yamt-pagecache-base2:1.106 yamt-pagecache:1.106.0.2 yamt-pagecache-base:1.106 cherry-xenmp:1.99.0.4 cherry-xenmp-base:1.99 bouyer-quota2-nbase:1.99 bouyer-quota2:1.99.0.2 bouyer-quota2-base:1.99 matt-mips64-premerge-20101231:1.99 matt-nb5-mips64-premerge-20101231:1.87.18.1.4.1 matt-nb5-pq3:1.87.18.3.0.4 matt-nb5-pq3-base:1.87.18.3 netbsd-5-1:1.87.18.3.0.2 netbsd-5-1-RELEASE:1.87.18.3 netbsd-5-1-RC4:1.87.18.3 matt-nb5-mips64-k15:1.87.18.1.4.1 netbsd-5-1-RC3:1.87.18.3 netbsd-5-1-RC2:1.87.18.3 netbsd-5-1-RC1:1.87.18.3 netbsd-5-0-2-RELEASE:1.87.18.1 matt-nb5-mips64-premerge-20091211:1.87.18.1 matt-premerge-20091211:1.93 matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.87.18.1 matt-nb4-mips64-k7-u2a-k9b:1.87.18.1 matt-nb5-mips64-u1-k1-k5:1.87.18.1 matt-nb5-mips64:1.87.18.1.0.4 netbsd-5-0-1-RELEASE:1.87.18.1 jym-xensuspend-nbase:1.93 netbsd-5-0:1.87.18.1.0.2 netbsd-5-0-RELEASE:1.87.18.1 netbsd-5-0-RC4:1.87.18.1 netbsd-5-0-RC3:1.87 netbsd-5-0-RC2:1.87 jym-xensuspend:1.88.0.2 jym-xensuspend-base:1.93 netbsd-5-0-RC1:1.87 netbsd-5:1.87.0.18 netbsd-5-base:1.87 matt-mips64-base2:1.87 matt-mips64:1.87.0.16 mjf-devfs2:1.87.0.14 mjf-devfs2-base:1.87 netbsd-4-0-1-RELEASE:1.85.2.1 wrstuden-revivesa-base-3:1.87 wrstuden-revivesa-base-2:1.87 wrstuden-fixsa-newbase:1.85.2.1 wrstuden-revivesa-base-1:1.87 yamt-pf42-base4:1.87 yamt-pf42-base3:1.87 hpcarm-cleanup-nbase:1.87 yamt-pf42-baseX:1.87 yamt-pf42-base2:1.87 wrstuden-revivesa:1.87.0.12 wrstuden-revivesa-base:1.87 yamt-pf42:1.87.0.10 yamt-pf42-base:1.87 keiichi-mipv6:1.87.0.8 keiichi-mipv6-base:1.87 matt-armv6-nbase:1.87 matt-armv6-prevmlocking:1.87 wrstuden-fixsa-base-1:1.85.2.1 netbsd-4-0:1.85.2.1.0.4 netbsd-4-0-RELEASE:1.85.2.1 cube-autoconf:1.87.0.6 cube-autoconf-base:1.87 netbsd-4-0-RC5:1.85.2.1 netbsd-4-0-RC4:1.85.2.1 netbsd-4-0-RC3:1.85.2.1 netbsd-4-0-RC2:1.85.2.1 netbsd-4-0-RC1:1.85.2.1 matt-armv6:1.87.0.4 matt-armv6-base:1.87 matt-mips64-base:1.87 hpcarm-cleanup:1.87.0.2 hpcarm-cleanup-base:1.87 netbsd-3-1-1-RELEASE:1.78 netbsd-3-0-3-RELEASE:1.78 wrstuden-fixsa:1.85.2.1.0.2 wrstuden-fixsa-base:1.85.2.1 abandoned-netbsd-4-base:1.84 abandoned-netbsd-4:1.84.0.2 netbsd-3-1:1.78.0.6 netbsd-3-1-RELEASE:1.78 netbsd-3-0-2-RELEASE:1.78 netbsd-3-1-RC4:1.78 netbsd-3-1-RC3:1.78 netbsd-3-1-RC2:1.78 netbsd-3-1-RC1:1.78 netbsd-4:1.85.0.2 netbsd-4-base:1.85 netbsd-3-0-1-RELEASE:1.78 netbsd-3-0:1.78.0.4 netbsd-3-0-RELEASE:1.78 netbsd-3-0-RC6:1.78 netbsd-3-0-RC5:1.78 netbsd-3-0-RC4:1.78 netbsd-3-0-RC3:1.78 netbsd-3-0-RC2:1.78 netbsd-3-0-RC1:1.78 netbsd-2-0-3-RELEASE:1.74 netbsd-2-1:1.74.0.6 netbsd-2-1-RELEASE:1.74 netbsd-2-1-RC6:1.74 netbsd-2-1-RC5:1.74 netbsd-2-1-RC4:1.74 netbsd-2-1-RC3:1.74 netbsd-2-1-RC2:1.74 netbsd-2-1-RC1:1.74 netbsd-2-0-2-RELEASE:1.74 netbsd-3:1.78.0.2 netbsd-3-base:1.78 netbsd-2-0-1-RELEASE:1.74 netbsd-2:1.74.0.4 netbsd-2-base:1.74 netbsd-2-0-RELEASE:1.74 netbsd-2-0-RC5:1.74 netbsd-2-0-RC4:1.74 netbsd-2-0-RC3:1.74 netbsd-2-0-RC2:1.74 netbsd-2-0-RC1:1.74 netbsd-2-0:1.74.0.2 netbsd-2-0-base:1.74 netbsd-1-6-PATCH002-RELEASE:1.49 netbsd-1-6-PATCH002:1.49 netbsd-1-6-PATCH002-RC4:1.49 netbsd-1-6-PATCH002-RC3:1.49 netbsd-1-6-PATCH002-RC2:1.49 netbsd-1-6-PATCH002-RC1:1.49 netbsd-1-6-PATCH001:1.49 netbsd-1-6-PATCH001-RELEASE:1.49 netbsd-1-6-PATCH001-RC3:1.49 netbsd-1-6-PATCH001-RC2:1.49 netbsd-1-6-PATCH001-RC1:1.49 fvdl_fs64_base:1.55 netbsd-1-6-RELEASE:1.49 netbsd-1-6-RC3:1.49 netbsd-1-6-RC2:1.49 netbsd-1-6-RC1:1.49 netbsd-1-6:1.49.0.2 netbsd-1-6-base:1.49 netbsd-1-5-PATCH003:1.33.4.7 ELRICshvfork:1.46.0.2 ELRICshvfork-base:1.46 netbsd-1-5-PATCH002:1.33.4.6 netbsd-1-5-PATCH001:1.33.4.6 netbsd-1-5-RELEASE:1.33.4.3 netbsd-1-5-BETA2:1.33.4.3 netbsd-1-5-BETA:1.33.4.3 netbsd-1-4-PATCH003:1.29 netbsd-1-5-ALPHA2:1.33.4.1 netbsd-1-5:1.33.0.4 netbsd-1-5-base:1.33 minoura-xpg4dl:1.33.0.2 minoura-xpg4dl-base:1.33 netbsd-1-4-PATCH002:1.29 wrstuden-devbsize-19991221:1.33 wrstuden-devbsize:1.30.0.2 wrstuden-devbsize-base:1.33 comdex-fall-1999:1.32.0.2 comdex-fall-1999-base:1.32 netbsd-1-4-PATCH001:1.29 netbsd-1-4-RELEASE:1.29 netbsd-1-4:1.29.0.2 netbsd-1-4-base:1.29 netbsd-1-3-PATCH003:1.21.2.1 netbsd-1-3-PATCH003-CANDIDATE2:1.21.2.1 netbsd-1-3-PATCH003-CANDIDATE1:1.21.2.1 netbsd-1-3-PATCH003-CANDIDATE0:1.21.2.1 netbsd-1-3-PATCH002:1.21.2.1 netbsd-1-3-PATCH001:1.21.2.1 netbsd-1-3-RELEASE:1.21.2.1 netbsd-1-3-BETA:1.21.2.1 netbsd-1-3:1.21.0.2 netbsd-1-3-base:1.21 netbsd-1-2-PATCH001:1.15.6.2 netbsd-1-2-RELEASE:1.15 netbsd-1-2-BETA:1.15 netbsd-1-2-base:1.15 netbsd-1-2:1.15.0.6 netbsd-1-1-PATCH001:1.15 netbsd-1-1-RELEASE:1.15 netbsd-1-1:1.15.0.2 netbsd-1-1-base:1.15 netbsd-1-0-PATCH06:1.11 netbsd-1-0-PATCH05:1.11 netbsd-1-0-PATCH04:1.11 netbsd-1-0-PATCH03:1.11 netbsd-1-0-PATCH02:1.11 netbsd-1-0-PATCH1:1.11 netbsd-1-0-PATCH0:1.11 netbsd-1-0-RELEASE:1.11 netbsd-1-0:1.11.0.2 netbsd-1-0-base:1.11 lite-1:1.1.1.2 CSRG:1.1.1 netbsd-0-9-RELEASE:1.5 netbsd-0-9-BETA:1.5 netbsd-0-9-ALPHA2:1.5 netbsd-0-9-ALPHA:1.5 netbsd-0-9:1.5.0.2 netbsd-0-9-base:1.5 netbsd-0-8:1.3 netbsd-alpha-1:1.3 patchkit-0-2-2:1.1.1.1 WFJ-386bsd-01:1.1.1.1 WFJ-920714:1.1.1; locks; strict; comment @.\" @; 1.259 date 2024.01.16.14.30.22; author kre; state Exp; branches; next 1.258; commitid FpkHfdMoJVJOlGUE; 1.258 date 2023.10.12.01.45.07; author uwe; state Exp; branches; next 1.257; commitid hnw9JQSBTLgwdhIE; 1.257 date 2023.09.01.01.57.54; author kre; state Exp; branches; next 1.256; commitid vWkGC3uA5BmNz0DE; 1.256 date 2023.08.04.15.31.40; author jschauma; state Exp; branches; next 1.255; commitid MmEQxu4RvKgr0uzE; 1.255 date 2022.12.20.17.51.54; author kre; state Exp; branches; next 1.254; commitid jUiOOymMEins4k6E; 1.254 date 2022.12.20.16.48.57; author kre; state Exp; branches; next 1.253; commitid 3yaHiCg0Cz0cJj6E; 1.253 date 2022.12.20.01.18.42; author uwe; state Exp; branches; next 1.252; commitid JAfjTlWXiUIlAe6E; 1.252 date 2022.12.11.08.23.10; author kre; state Exp; branches 1.252.2.1; next 1.251; commitid WbSH98SUFUG5c75E; 1.251 date 2022.10.30.01.19.08; author kre; state Exp; branches; next 1.250; commitid wATodtnkr2WndGZD; 1.250 date 2022.09.18.06.03.19; author kre; state Exp; branches; next 1.249; commitid CRPUJDYfi7ek9jUD; 1.249 date 2022.09.16.19.25.09; author kre; state Exp; branches; next 1.248; commitid HHYCiqskxoviE7UD; 1.248 date 2022.09.16.17.32.18; author kre; state Exp; branches; next 1.247; commitid wPri3UwMwWAi17UD; 1.247 date 2022.09.16.17.29.21; author kre; state Exp; branches; next 1.246; commitid 990iRWsTvf3a07UD; 1.246 date 2022.09.16.17.25.09; author kre; state Exp; branches; next 1.245; commitid 9lR3cte0X0QaZ6UD; 1.245 date 2022.09.15.18.00.36; author kre; state Exp; branches; next 1.244; commitid o19V6eMci5AcdZTD; 1.244 date 2022.08.19.13.37.03; author kre; state Exp; branches; next 1.243; commitid Ir9GLWaVgIUDCuQD; 1.243 date 2022.01.07.05.30.30; author lukem; state Exp; branches; next 1.242; commitid RKSnotYzCnxp7FnD; 1.242 date 2022.01.07.05.10.30; author lukem; state Exp; branches; next 1.241; commitid pTGnyiTQYRln1FnD; 1.241 date 2021.11.21.16.23.20; author kre; state Exp; branches; next 1.240; commitid C6TFQb1BnVcKfGhD; 1.240 date 2021.11.20.17.18.31; author rillig; state Exp; branches; next 1.239; commitid 8XdVeKPgvSVHAyhD; 1.239 date 2021.11.20.01.52.51; author kre; state Exp; branches; next 1.238; commitid vIIQNtd4VnZfsthD; 1.238 date 2021.11.16.23.39.34; author rillig; state Exp; branches; next 1.237; commitid dU6SBUkdm5BuP4hD; 1.237 date 2021.11.16.11.28.29; author kre; state Exp; branches; next 1.236; commitid BUyf1k1h15ZHM0hD; 1.236 date 2021.10.31.02.12.08; author kre; state Exp; branches; next 1.235; commitid 8mBACpETi8qJdUeD; 1.235 date 2021.10.26.00.05.38; author kre; state Exp; branches; next 1.234; commitid sCfEzZl2p4RhGfeD; 1.234 date 2021.09.15.18.30.57; author kre; state Exp; branches; next 1.233; commitid F7alOlrt1cec759D; 1.233 date 2021.09.12.06.53.08; author wiz; state Exp; branches; next 1.232; commitid RDLWOQSUsTMLlD8D; 1.232 date 2021.09.12.02.20.36; author kre; state Exp; branches; next 1.231; commitid kumLfkZE3PHEPB8D; 1.231 date 2021.09.12.01.30.41; author kre; state Exp; branches; next 1.230; commitid g8N4bJAuXq8iyB8D; 1.230 date 2021.09.11.20.43.32; author christos; state Exp; branches; next 1.229; commitid bm918sBvV5zDYz8D; 1.229 date 2020.09.18.07.21.26; author wiz; state Exp; branches; next 1.228; commitid GkioMzcDlriV2voC; 1.228 date 2020.09.18.06.48.28; author kre; state Exp; branches; next 1.227; commitid Q8vmUp3ofHyhQuoC; 1.227 date 2020.08.25.19.42.02; author kre; state Exp; branches; next 1.226; commitid kCmSUY6G4nHGUtlC; 1.226 date 2020.08.21.08.14.45; author wiz; state Exp; branches; next 1.225; commitid zdSPii8xZ8uZeUkC; 1.225 date 2020.08.20.23.19.34; author kre; state Exp; branches; next 1.224; commitid JleDfp8AS2omfRkC; 1.224 date 2020.02.20.18.24.20; author pgoyette; state Exp; branches; next 1.223; commitid 7HlsJ2IJh9XNurXB; 1.223 date 2019.04.22.04.10.33; author kre; state Exp; branches 1.223.2.1; next 1.222; commitid edCqlu0CmgzKxikB; 1.222 date 2019.04.22.04.04.35; author kre; state Exp; branches; next 1.221; commitid JIQEH8Ng76IQuikB; 1.221 date 2019.04.15.20.35.25; author uwe; state Exp; branches; next 1.220; commitid BTij6ve3nEOAdujB; 1.220 date 2019.02.14.11.15.24; author kre; state Exp; branches; next 1.219; commitid og7i04xXJ1kt0JbB; 1.219 date 2019.02.04.12.18.36; author wiz; state Exp; branches; next 1.218; commitid MuR0uW3AjlzFIraB; 1.218 date 2019.02.04.11.16.41; author kre; state Exp; branches; next 1.217; commitid nmgMzBlc0lZpnraB; 1.217 date 2019.01.21.14.09.24; author kre; state Exp; branches; next 1.216; commitid RTkCCKWxXY1CLE8B; 1.216 date 2018.12.12.20.22.43; author kre; state Exp; branches; next 1.215; commitid ekXsxbUdmuZm8y3B; 1.215 date 2018.12.12.12.56.17; author kre; state Exp; branches; next 1.214; commitid URZemcByPZwCEv3B; 1.214 date 2018.12.12.12.30.59; author kre; state Exp; branches; next 1.213; commitid wMbmIHk3I9Zewv3B; 1.213 date 2018.12.12.11.51.33; author kre; state Exp; branches; next 1.212; commitid 95uc5XQLarW1jv3B; 1.212 date 2018.12.11.13.31.20; author kre; state Exp; branches; next 1.211; commitid SHYt7MVJeFUfTn3B; 1.211 date 2018.12.04.14.03.30; author kre; state Exp; branches; next 1.210; commitid YawVMoRs6EBdiu2B; 1.210 date 2018.12.03.06.43.19; author kre; state Exp; branches; next 1.209; commitid 53ik6IoVlWQdTj2B; 1.209 date 2018.11.23.20.40.06; author kre; state Exp; branches; next 1.208; commitid tn0rB8zonrnPP61B; 1.208 date 2018.09.04.23.16.30; author kre; state Exp; branches; next 1.207; commitid iOkFZWGg39QihQQA; 1.207 date 2018.08.25.17.35.31; author kre; state Exp; branches; next 1.206; commitid ArkYt6nhO3YcCwPA; 1.206 date 2018.05.03.05.11.43; author wiz; state Exp; branches 1.206.2.1; next 1.205; commitid KYuVJnFHTEGggOAA; 1.205 date 2018.05.03.00.32.11; author kre; state Exp; branches; next 1.204; commitid EEDlhIwz7IlcIMAA; 1.204 date 2018.05.02.21.43.38; author pgoyette; state Exp; branches; next 1.203; commitid msNsK5LRxSUmMLAA; 1.203 date 2018.03.17.01.53.06; author uwe; state Exp; branches; next 1.202; commitid ZTRJJlhr4X9OFKuA; 1.202 date 2018.03.17.01.40.28; author uwe; state Exp; branches; next 1.201; commitid HQJTO5r6yxFtBKuA; 1.201 date 2018.03.17.01.32.42; author uwe; state Exp; branches; next 1.200; commitid aXVyDiUvTyWNyKuA; 1.200 date 2018.03.17.01.03.08; author uwe; state Exp; branches; next 1.199; commitid JLbTRBAy2pzFoKuA; 1.199 date 2018.03.17.00.03.25; author uwe; state Exp; branches; next 1.198; commitid Nxnrw0rOxPfb4KuA; 1.198 date 2018.03.16.23.56.13; author uwe; state Exp; branches; next 1.197; commitid 97tFkK9CE7eI1KuA; 1.197 date 2018.03.16.23.36.13; author uwe; state Exp; branches; next 1.196; commitid mFAH7vevKdNQUJuA; 1.196 date 2018.03.16.12.06.18; author kre; state Exp; branches; next 1.195; commitid Q65PSjP7q0CX5GuA; 1.195 date 2018.03.16.11.53.57; author kre; state Exp; branches; next 1.194; commitid 63IRnBXb6vfu1GuA; 1.194 date 2018.03.16.11.19.24; author kre; state Exp; branches; next 1.193; commitid OnuOeOMzssLLPFuA; 1.193 date 2018.03.15.01.20.43; author uwe; state Exp; branches; next 1.192; commitid D5voDiZQ7sUFyuuA; 1.192 date 2018.03.14.10.38.52; author uwe; state Exp; branches; next 1.191; commitid XVBtiQ82X4A9GpuA; 1.191 date 2018.03.14.10.30.40; author uwe; state Exp; branches; next 1.190; commitid 9o0QyS0QaRYjDpuA; 1.190 date 2018.03.14.09.46.45; author uwe; state Exp; branches; next 1.189; commitid resIvEKSTnHgopuA; 1.189 date 2018.03.14.09.42.37; author uwe; state Exp; branches; next 1.188; commitid rOGkjyVMagzQmpuA; 1.188 date 2018.03.14.07.53.14; author wiz; state Exp; branches; next 1.187; commitid 2Do67TbbFJgjLouA; 1.187 date 2018.03.13.23.03.21; author uwe; state Exp; branches; next 1.186; commitid Y14MZuEf4fixPluA; 1.186 date 2018.03.13.21.49.15; author uwe; state Exp; branches; next 1.185; commitid oqiNoW7mTTb8qluA; 1.185 date 2018.03.13.21.04.57; author uwe; state Exp; branches; next 1.184; commitid 2l5wGasVYrLValuA; 1.184 date 2018.03.13.20.48.00; author uwe; state Exp; branches; next 1.183; commitid esd4AKDzLg375luA; 1.183 date 2018.03.13.20.40.52; author uwe; state Exp; branches; next 1.182; commitid jMzS1zGv505F2luA; 1.182 date 2018.03.13.20.39.25; author uwe; state Exp; branches; next 1.181; commitid sVBRPA7C9pQ92luA; 1.181 date 2018.03.13.20.29.13; author uwe; state Exp; branches; next 1.180; commitid hLFxJP0qvYYEYkuA; 1.180 date 2018.03.13.20.18.16; author uwe; state Exp; branches; next 1.179; commitid D1jvDl99YpwUUkuA; 1.179 date 2018.03.13.20.08.11; author uwe; state Exp; branches; next 1.178; commitid gVoa7aVYwZVrRkuA; 1.178 date 2018.03.13.19.43.52; author uwe; state Exp; branches; next 1.177; commitid pFmJQo8aJcx6JkuA; 1.177 date 2018.03.13.19.35.46; author uwe; state Exp; branches; next 1.176; commitid lVx3iKNl3YBjGkuA; 1.176 date 2018.03.13.19.18.53; author uwe; state Exp; branches; next 1.175; commitid 5dBAZ8Ny1s9xAkuA; 1.175 date 2018.01.15.11.27.39; author kre; state Exp; branches 1.175.2.1; next 1.174; commitid pllJFc4Id35KNXmA; 1.174 date 2017.11.19.03.23.01; author kre; state Exp; branches; next 1.173; commitid LupVPv670GYOXAfA; 1.173 date 2017.11.15.08.50.07; author kre; state Exp; branches; next 1.172; commitid mUaYu9APRH6LT6fA; 1.172 date 2017.10.30.15.37.41; author wiz; state Exp; branches; next 1.171; commitid lMPMxdMv7ZFFF5dA; 1.171 date 2017.10.29.00.20.42; author kre; state Exp; branches; next 1.170; commitid tikOgucrEs72DScA; 1.170 date 2017.10.28.06.36.17; author kre; state Exp; branches; next 1.169; commitid f8VFze686FAVJMcA; 1.169 date 2017.10.25.05.42.56; author kre; state Exp; branches; next 1.168; commitid vq9hiKtQMb9CxocA; 1.168 date 2017.10.15.12.01.43; author pgoyette; state Exp; branches; next 1.167; commitid pDaWsPXVRSnmX8bA; 1.167 date 2017.10.06.21.09.45; author kre; state Exp; branches; next 1.166; commitid IHOAGYpbx37rh2aA; 1.166 date 2017.08.27.20.37.59; author wiz; state Exp; branches; next 1.165; commitid pEY10Jajap24oT4A; 1.165 date 2017.08.27.20.32.20; author wiz; state Exp; branches; next 1.164; commitid IFvMXTsmq4IkmT4A; 1.164 date 2017.08.21.13.20.49; author kre; state Exp; branches; next 1.163; commitid 9TaSnGuQXXeea54A; 1.163 date 2017.07.25.08.37.48; author wiz; state Exp; branches; next 1.162; commitid McBlZdXgsEOYsA0A; 1.162 date 2017.07.24.14.17.11; author kre; state Exp; branches; next 1.161; commitid u7iXJbDjm8nonu0A; 1.161 date 2017.07.24.13.21.14; author kre; state Exp; branches; next 1.160; commitid drQQzcBVrZdb4u0A; 1.160 date 2017.07.24.12.36.02; author kre; state Exp; branches; next 1.159; commitid wa1nu8iPNvBGOt0A; 1.159 date 2017.07.01.05.11.57; author wiz; state Exp; branches; next 1.158; commitid kLW4jAee8YX36uXz; 1.158 date 2017.06.30.23.48.50; author kre; state Exp; branches; next 1.157; commitid 55looMpvzWhbjsXz; 1.157 date 2017.06.30.23.07.29; author kre; state Exp; branches; next 1.156; commitid 4JMiFoDNmfkD4sXz; 1.156 date 2017.06.28.13.46.06; author kre; state Exp; branches; next 1.155; commitid JgXsbLAWc8A529Xz; 1.155 date 2017.06.27.12.43.44; author kre; state Exp; branches; next 1.154; commitid tMmzAVpTV8mDI0Xz; 1.154 date 2017.06.27.08.30.40; author wiz; state Exp; branches; next 1.153; commitid NzEZsMraElgakZWz; 1.153 date 2017.06.27.02.22.08; author kre; state Exp; branches; next 1.152; commitid a0CAYBSyIt8phXWz; 1.152 date 2017.06.17.07.50.35; author kre; state Exp; branches; next 1.151; commitid QLKqLx0KFL8uqHVz; 1.151 date 2017.06.08.02.23.51; author kre; state Exp; branches; next 1.150; commitid nWcoq5x4ybf5UvUz; 1.150 date 2017.06.07.13.49.48; author wiz; state Exp; branches; next 1.149; commitid 7c1zMNSgyINFJrUz; 1.149 date 2017.06.07.05.08.32; author kre; state Exp; branches; next 1.148; commitid ovDy4KCysFHNQoUz; 1.148 date 2017.06.06.22.38.52; author kre; state Exp; branches; next 1.147; commitid f5UWTMJ52cnYGmUz; 1.147 date 2017.06.04.20.27.14; author kre; state Exp; branches; next 1.146; commitid QajWwzQwrWiZ16Uz; 1.146 date 2017.06.02.17.42.51; author abhinav; state Exp; branches 1.146.2.1; next 1.145; commitid O7iI7FvviheybPTz; 1.145 date 2017.05.27.11.19.57; author kre; state Exp; branches; next 1.144; commitid K6mCnk2dSKpbg1Tz; 1.144 date 2017.05.27.06.32.12; author kre; state Exp; branches; next 1.143; commitid 3k55SYb6Li5mFZSz; 1.143 date 2017.05.18.13.56.58; author kre; state Exp; branches; next 1.142; commitid p1OJ0bijg6DvpSRz; 1.142 date 2017.05.18.13.53.18; author kre; state Exp; branches; next 1.141; commitid yUyV05aWV3qPiSRz; 1.141 date 2017.05.14.17.27.05; author kre; state Exp; branches; next 1.140; commitid HsViAHnG7qEEHnRz; 1.140 date 2017.05.14.14.14.39; author kre; state Exp; branches; next 1.139; commitid G7zy6W34cH7dDmRz; 1.139 date 2017.05.14.10.53.26; author wiz; state Exp; branches; next 1.138; commitid KLbRTXl2Ai0XwlRz; 1.138 date 2017.05.12.08.55.38; author kre; state Exp; branches; next 1.137; commitid e4v1QCjsQE0RV4Rz; 1.137 date 2017.05.12.08.39.47; author kre; state Exp; branches; next 1.136; commitid RURLbp7MDD4tQ4Rz; 1.136 date 2017.05.07.15.01.18; author kre; state Exp; branches; next 1.135; commitid xHczW4ZyjAXS7tQz; 1.135 date 2017.05.04.04.37.51; author kre; state Exp; branches; next 1.134; commitid N4FUUgQL8INKL1Qz; 1.134 date 2017.05.03.00.43.22; author kre; state Exp; branches; next 1.133; commitid zDd78Gj6SfjmvSPz; 1.133 date 2017.04.30.16.02.48; author wiz; state Exp; branches; next 1.132; commitid r9jZ8XKjnRTZGzPz; 1.132 date 2017.04.29.15.26.44; author kre; state Exp; branches; next 1.131; commitid ndaJUgCoqqUmwrPz; 1.131 date 2017.04.14.08.48.01; author abhinav; state Exp; branches 1.131.2.1; next 1.130; commitid 38LxM3NGuHStNtNz; 1.130 date 2017.04.14.08.40.30; author abhinav; state Exp; branches; next 1.129; commitid wASEJfG1fLMWItNz; 1.129 date 2017.04.03.14.08.37; author abhinav; state Exp; branches; next 1.128; commitid xR7ykEuz9v3GT5Mz; 1.128 date 2017.03.23.12.10.53; author kre; state Exp; branches; next 1.127; commitid AgBzRcjdZXQlCFKz; 1.127 date 2017.03.20.22.17.56; author kre; state Exp; branches; next 1.126; commitid 7yh3sMOgP9aU4lKz; 1.126 date 2017.03.20.11.26.07; author kre; state Exp; branches; next 1.125; commitid qdyVtLbJohMZrhKz; 1.125 date 2017.02.04.23.35.15; author wiz; state Exp; branches; next 1.124; commitid F65J7gebLTMDVGEz; 1.124 date 2017.02.02.20.00.40; author christos; state Exp; branches; next 1.123; commitid FV7Vp8x26V2MNpEz; 1.123 date 2016.05.12.13.15.43; author kre; state Exp; branches 1.123.2.1 1.123.4.1; next 1.122; commitid ApdcrJt2ok414c6z; 1.122 date 2016.05.09.20.36.07; author kre; state Exp; branches; next 1.121; commitid w6ZPqCRgVBVaDQ5z; 1.121 date 2016.04.04.13.05.56; author wiz; state Exp; branches; next 1.120; commitid 7ngjORw7hrlvhj1z; 1.120 date 2016.03.31.16.18.22; author christos; state Exp; branches; next 1.119; commitid Ck0Smut06IdvtO0z; 1.119 date 2016.02.24.15.28.36; author wiz; state Exp; branches; next 1.118; commitid 75F38VXaPMIembWy; 1.118 date 2016.02.24.14.35.51; author christos; state Exp; branches; next 1.117; commitid 1OJNnugTyOV93bWy; 1.117 date 2016.01.06.00.22.21; author wiz; state Exp; branches; next 1.116; commitid O61JU43DtRqZUNPy; 1.116 date 2016.01.05.18.16.20; author christos; state Exp; branches; next 1.115; commitid Uu2joPodZi8lTLPy; 1.115 date 2015.05.26.21.35.15; author christos; state Exp; branches; next 1.114; commitid ZLUBkEesJyB9a0ny; 1.114 date 2014.06.01.17.46.06; author christos; state Exp; branches; next 1.113; commitid LZUpcIaS87RvsQCx; 1.113 date 2014.05.31.14.42.18; author christos; state Exp; branches; next 1.112; commitid LMUbFY5TnxjttHCx; 1.112 date 2014.01.20.14.05.51; author roy; state Exp; branches 1.112.2.1; next 1.111; commitid iE2jGOSeq1svtRlx; 1.111 date 2013.10.02.20.42.56; author christos; state Exp; branches; next 1.110; commitid PSgrt772p05zdL7x; 1.110 date 2013.05.09.11.43.27; author simonb; state Exp; branches; next 1.109; 1.109 date 2012.10.03.19.37.36; author wiz; state Exp; branches; next 1.108; 1.108 date 2012.08.26.14.30.38; author wiz; state Exp; branches 1.108.2.1; next 1.107; 1.107 date 2012.06.11.18.28.10; author njoly; state Exp; branches; next 1.106; 1.106 date 2011.10.05.13.15.30; author christos; state Exp; branches 1.106.2.1; next 1.105; 1.105 date 2011.10.04.18.11.27; author apb; state Exp; branches; next 1.104; 1.104 date 2011.10.04.18.07.39; author christos; state Exp; branches; next 1.103; 1.103 date 2011.09.11.06.02.20; author dholland; state Exp; branches; next 1.102; 1.102 date 2011.06.13.20.41.00; author wiz; state Exp; branches; next 1.101; 1.101 date 2011.06.13.00.17.15; author uebayasi; state Exp; branches; next 1.100; 1.100 date 2011.06.11.14.37.36; author christos; state Exp; branches; next 1.99; 1.99 date 2010.06.03.02.05.02; author dholland; state Exp; branches 1.99.4.1; next 1.98; 1.98 date 2010.03.01.21.53.58; author joerg; state Exp; branches; next 1.97; 1.97 date 2010.01.01.21.46.31; author wiz; state Exp; branches; next 1.96; 1.96 date 2010.01.01.19.51.19; author dholland; state Exp; branches; next 1.95; 1.95 date 2010.01.01.19.34.59; author dholland; state Exp; branches; next 1.94; 1.94 date 2010.01.01.18.09.16; author dholland; state Exp; branches; next 1.93; 1.93 date 2009.03.29.08.55.27; author wiz; state Exp; branches; next 1.92; 1.92 date 2009.03.29.01.02.49; author mrg; state Exp; branches; next 1.91; 1.91 date 2009.03.10.15.14.28; author joerg; state Exp; branches; next 1.90; 1.90 date 2009.03.10.14.18.52; author joerg; state Exp; branches; next 1.89; 1.89 date 2009.03.09.19.24.26; author joerg; state Exp; branches; next 1.88; 1.88 date 2008.12.11.04.34.45; author yamt; state Exp; branches 1.88.2.1; next 1.87; 1.87 date 2007.06.24.17.57.56; author christos; state Exp; branches 1.87.18.1; next 1.86; 1.86 date 2007.03.25.06.56.43; author apb; state Exp; branches; next 1.85; 1.85 date 2006.09.04.20.30.36; author dsl; state Exp; branches 1.85.2.1; next 1.84; 1.84 date 2005.09.10.22.09.43; author wiz; state Exp; branches; next 1.83; 1.83 date 2005.08.20.21.07.42; author dsl; state Exp; branches; next 1.82; 1.82 date 2005.07.15.22.33.48; author wiz; state Exp; branches; next 1.81; 1.81 date 2005.07.15.17.23.48; author christos; state Exp; branches; next 1.80; 1.80 date 2005.05.24.00.03.52; author wiz; state Exp; branches; next 1.79; 1.79 date 2005.05.07.19.52.17; author dsl; state Exp; branches; next 1.78; 1.78 date 2004.06.03.19.54.37; author hubertf; state Exp; branches; next 1.77; 1.77 date 2004.04.23.13.28.15; author wiz; state Exp; branches; next 1.76; 1.76 date 2004.04.17.15.42.42; author wiz; state Exp; branches; next 1.75; 1.75 date 2004.04.17.15.41.29; author christos; state Exp; branches; next 1.74; 1.74 date 2003.12.21.11.16.23; author wiz; state Exp; branches; next 1.73; 1.73 date 2003.12.21.08.40.29; author jdolecek; state Exp; branches; next 1.72; 1.72 date 2003.12.18.15.52.31; author heas; state Exp; branches; next 1.71; 1.71 date 2003.11.14.20.00.28; author dsl; state Exp; branches; next 1.70; 1.70 date 2003.10.27.08.23.40; author wiz; state Exp; branches; next 1.69; 1.69 date 2003.10.27.08.22.21; author wiz; state Exp; branches; next 1.68; 1.68 date 2003.08.07.09.05.37; author agc; state Exp; branches; next 1.67; 1.67 date 2003.06.27.09.11.12; author wiz; state Exp; branches; next 1.66; 1.66 date 2003.05.06.08.33.08; author wiz; state Exp; branches; next 1.65; 1.65 date 2003.05.04.01.05.24; author gmcgarry; state Exp; branches; next 1.64; 1.64 date 2003.05.02.09.00.14; author gmcgarry; state Exp; branches; next 1.63; 1.63 date 2003.04.12.16.39.19; author zuntum; state Exp; branches; next 1.62; 1.62 date 2003.03.22.11.37.49; author kristerw; state Exp; branches; next 1.61; 1.61 date 2003.02.25.10.34.41; author wiz; state Exp; branches; next 1.60; 1.60 date 2003.02.12.19.00.08; author wiz; state Exp; branches; next 1.59; 1.59 date 2003.02.12.02.55.14; author gmcgarry; state Exp; branches; next 1.58; 1.58 date 2003.01.23.18.32.07; author wiz; state Exp; branches; next 1.57; 1.57 date 2003.01.22.22.05.45; author wiz; state Exp; branches; next 1.56; 1.56 date 2003.01.22.20.36.04; author dsl; state Exp; branches; next 1.55; 1.55 date 2002.12.28.05.08.27; author uebayasi; state Exp; branches; next 1.54; 1.54 date 2002.12.19.18.04.41; author kleink; state Exp; branches; next 1.53; 1.53 date 2002.12.12.11.50.40; author uebayasi; state Exp; branches; next 1.52; 1.52 date 2002.10.02.10.01.46; author wiz; state Exp; branches; next 1.51; 1.51 date 2002.10.01.15.06.31; author wiz; state Exp; branches; next 1.50; 1.50 date 2002.09.25.15.18.42; author wiz; state Exp; branches; next 1.49; 1.49 date 2002.05.15.19.43.29; author bjh21; state Exp; branches; next 1.48; 1.48 date 2002.05.15.16.33.35; author christos; state Exp; branches; next 1.47; 1.47 date 2002.05.15.14.59.21; author christos; state Exp; branches; next 1.46; 1.46 date 2002.02.24.21.41.52; author lukem; state Exp; branches; next 1.45; 1.45 date 2002.02.08.01.21.59; author ross; state Exp; branches; next 1.44; 1.44 date 2001.12.20.20.07.40; author wiz; state Exp; branches; next 1.43; 1.43 date 2001.04.03.10.56.03; author wiz; state Exp; branches; next 1.42; 1.42 date 2001.04.01.02.15.45; author toddpw; state Exp; branches; next 1.41; 1.41 date 2001.03.18.04.04.23; author wulf; state Exp; branches; next 1.40; 1.40 date 2000.11.20.17.48.05; author christos; state Exp; branches; next 1.39; 1.39 date 2000.11.20.16.59.56; author christos; state Exp; branches; next 1.38; 1.38 date 2000.09.21.21.04.56; author phil; state Exp; branches; next 1.37; 1.37 date 2000.09.04.07.30.12; author kleink; state Exp; branches; next 1.36; 1.36 date 2000.08.28.02.11.06; author hubertf; state Exp; branches; next 1.35; 1.35 date 2000.07.18.01.55.48; author jhawk; state Exp; branches; next 1.34; 1.34 date 2000.07.17.21.18.47; author jhawk; state Exp; branches; next 1.33; 1.33 date 99.11.16.22.03.25; author hubertf; state Exp; branches 1.33.4.1; next 1.32; 1.32 date 99.09.28.14.54.43; author bouyer; state Exp; branches; next 1.31; 1.31 date 99.09.27.19.34.25; author mjl; state Exp; branches; next 1.30; 1.30 date 99.07.06.14.01.01; author christos; state Exp; branches 1.30.2.1; next 1.29; 1.29 date 99.03.23.02.29.29; author ross; state Exp; branches; next 1.28; 1.28 date 99.02.04.00.27.07; author cjs; state Exp; branches; next 1.27; 1.27 date 99.01.28.18.11.50; author kleink; state Exp; branches; next 1.26; 1.26 date 99.01.11.19.34.53; author garbled; state Exp; branches; next 1.25; 1.25 date 98.11.17.14.16.32; author msaitoh; state Exp; branches; next 1.24; 1.24 date 98.10.29.23.23.36; author garbled; state Exp; branches; next 1.23; 1.23 date 98.07.04.06.52.07; author ross; state Exp; branches; next 1.22; 1.22 date 97.11.05.14.05.31; author kleink; state Exp; branches; next 1.21; 1.21 date 97.07.10.23.07.04; author phil; state Exp; branches 1.21.2.1; next 1.20; 1.20 date 97.05.23.19.40.30; author cjs; state Exp; branches; next 1.19; 1.19 date 97.03.08.13.28.45; author mouse; state Exp; branches; next 1.18; 1.18 date 97.02.06.23.24.54; author christos; state Exp; branches; next 1.17; 1.17 date 96.10.16.15.20.01; author christos; state Exp; branches; next 1.16; 1.16 date 96.09.02.21.28.21; author christos; state Exp; branches; next 1.15; 1.15 date 95.05.11.21.30.18; author christos; state Exp; branches 1.15.6.1; next 1.14; 1.14 date 95.03.21.09.10.12; author cgd; state Exp; branches; next 1.13; 1.13 date 95.01.23.06.33.08; author christos; state Exp; branches; next 1.12; 1.12 date 95.01.12.23.35.56; author jtc; state Exp; branches; next 1.11; 1.11 date 94.06.11.16.12.33; author mycroft; state Exp; branches; next 1.10; 1.10 date 94.05.11.17.10.41; author jtc; state Exp; branches; next 1.9; 1.9 date 94.05.04.23.49.12; author jtc; state Exp; branches; next 1.8; 1.8 date 94.02.03.17.47.48; author jtc; state Exp; branches; next 1.7; 1.7 date 94.01.27.17.53.28; author jtc; state Exp; branches; next 1.6; 1.6 date 93.08.01.07.58.14; author mycroft; state Exp; branches; next 1.5; 1.5 date 93.05.02.23.08.42; author mycroft; state Exp; branches; next 1.4; 1.4 date 93.04.22.03.27.28; author mycroft; state Exp; branches; next 1.3; 1.3 date 93.03.23.00.29.20; author cgd; state Exp; branches; next 1.2; 1.2 date 93.03.22.08.04.00; author cgd; state Exp; branches; next 1.1; 1.1 date 93.03.21.09.45.37; author cgd; state Exp; branches 1.1.1.1; next ; 1.252.2.1 date 2022.12.20.09.51.47; author martin; state Exp; branches; next ; commitid pWhkwxAaKxjnqh6E; 1.223.2.1 date 2021.11.06.13.35.43; author martin; state Exp; branches; next 1.223.2.2; commitid 3ld6peNZ1aHgOJfD; 1.223.2.2 date 2021.11.06.13.42.18; author martin; state Exp; branches; next ; commitid F9cK3NVDLDoxQJfD; 1.206.2.1 date 2019.06.10.21.41.04; author christos; state Exp; branches; next 1.206.2.2; commitid jtc8rnCzWiEEHGqB; 1.206.2.2 date 2020.04.08.14.03.04; author martin; state Exp; branches; next 1.206.2.3; commitid Qli2aW9E74UFuA3C; 1.206.2.3 date 2020.04.21.18.41.06; author martin; state dead; branches; next 1.206.2.4; commitid 86tA4aEmdr3VCh5C; 1.206.2.4 date 2020.04.21.19.37.34; author martin; state Exp; branches; next ; commitid x6IB64bYH9UmWh5C; 1.175.2.1 date 2018.03.15.09.11.52; author pgoyette; state Exp; branches; next 1.175.2.2; commitid lb7w3QtkrVH4axuA; 1.175.2.2 date 2018.03.22.01.44.39; author pgoyette; state Exp; branches; next 1.175.2.3; commitid fxb4Rxa9G9QMsovA; 1.175.2.3 date 2018.05.21.04.35.48; author pgoyette; state Exp; branches; next 1.175.2.4; commitid X5L8kSrBWQcDt7DA; 1.175.2.4 date 2018.09.06.06.51.32; author pgoyette; state Exp; branches; next 1.175.2.5; commitid HCi1bXD317XIK0RA; 1.175.2.5 date 2018.11.26.01.49.54; author pgoyette; state Exp; branches; next 1.175.2.6; commitid Zj4q5SspGdKXto1B; 1.175.2.6 date 2018.12.26.14.01.03; author pgoyette; state Exp; branches; next 1.175.2.7; commitid xUhK8IAeBM1azj5B; 1.175.2.7 date 2019.01.26.21.58.12; author pgoyette; state Exp; branches; next ; commitid JKpcmvSjdT25dl9B; 1.146.2.1 date 2017.06.05.08.10.24; author snj; state Exp; branches; next 1.146.2.2; commitid yje29erFdDiWU9Uz; 1.146.2.2 date 2017.06.09.16.53.39; author snj; state Exp; branches; next 1.146.2.3; commitid UUSTs1lwweYJGIUz; 1.146.2.3 date 2017.07.23.14.58.14; author snj; state Exp; branches; next 1.146.2.4; commitid IcSSefq8ASq6Dm0A; 1.146.2.4 date 2017.10.25.06.51.36; author snj; state Exp; branches; next 1.146.2.5; commitid ksSe7lrJhH37VocA; 1.146.2.5 date 2017.10.25.07.03.10; author snj; state Exp; branches; next 1.146.2.6; commitid bDzNSHxPgSa8ZocA; 1.146.2.6 date 2018.12.07.13.23.49; author martin; state Exp; branches; next ; commitid 559Nxwr8NXoEYR2B; 1.131.2.1 date 2017.05.02.03.19.14; author pgoyette; state Exp; branches; next 1.131.2.2; commitid oFKELrgrBgUNoLPz; 1.131.2.2 date 2017.05.11.02.58.28; author pgoyette; state Exp; branches; next 1.131.2.3; commitid p6b6NO9zXediZUQz; 1.131.2.3 date 2017.05.19.00.22.51; author pgoyette; state Exp; branches; next ; commitid QNTxgGjVagwoSVRz; 1.123.2.1 date 2017.03.20.06.51.32; author pgoyette; state Exp; branches; next 1.123.2.2; commitid jjw7cAwgyKq7RfKz; 1.123.2.2 date 2017.04.26.02.52.13; author pgoyette; state Exp; branches; next ; commitid ojV02aOSdzvBqZOz; 1.123.4.1 date 2017.04.21.16.50.42; author bouyer; state Exp; branches; next ; commitid dUG7nkTKALCadqOz; 1.112.2.1 date 2014.08.10.06.41.18; author tls; state Exp; branches; next ; commitid cmSmsS7FIRrlxMLx; 1.108.2.1 date 2012.11.20.02.57.28; author tls; state Exp; branches; next 1.108.2.2; 1.108.2.2 date 2013.06.23.06.26.13; author tls; state Exp; branches; next 1.108.2.3; commitid OnlO1cBgtQRcIHUw; 1.108.2.3 date 2014.08.19.23.45.11; author tls; state Exp; branches; next ; commitid jTnpym9Qu0o4R1Nx; 1.106.2.1 date 2012.10.30.18.46.08; author yamt; state Exp; branches; next 1.106.2.2; 1.106.2.2 date 2014.05.22.11.26.23; author yamt; state Exp; branches; next ; commitid OarWMuV9WFtzGwBx; 1.99.4.1 date 2011.06.23.14.17.48; author cherry; state Exp; branches; next ; 1.88.2.1 date 2009.05.13.19.15.51; author jym; state Exp; branches; next ; 1.87.18.1 date 2009.04.01.00.25.21; author snj; state Exp; branches 1.87.18.1.4.1; next 1.87.18.2; 1.87.18.2 date 2010.01.30.19.24.32; author snj; state Exp; branches; next 1.87.18.3; 1.87.18.3 date 2010.01.30.19.26.39; author snj; state Exp; branches; next ; 1.87.18.1.4.1 date 2010.04.21.05.15.28; author matt; state Exp; branches; next ; 1.85.2.1 date 2007.04.16.19.33.51; author bouyer; state Exp; branches; next 1.85.2.2; 1.85.2.2 date 2010.01.27.21.01.58; author bouyer; state Exp; branches; next ; 1.33.4.1 date 2000.07.18.01.59.14; author jhawk; state Exp; branches; next 1.33.4.2; 1.33.4.2 date 2000.08.28.04.25.47; author hubertf; state Exp; branches; next 1.33.4.3; 1.33.4.3 date 2000.09.21.21.32.35; author phil; state Exp; branches; next 1.33.4.4; 1.33.4.4 date 2001.03.17.10.21.33; author wulf; state Exp; branches; next 1.33.4.5; 1.33.4.5 date 2001.03.18.03.20.12; author wulf; state Exp; branches; next 1.33.4.6; 1.33.4.6 date 2001.04.04.16.15.24; author he; state Exp; branches; next 1.33.4.7; 1.33.4.7 date 2002.02.23.15.54.10; author he; state Exp; branches; next ; 1.30.2.1 date 99.12.27.18.27.12; author wrstuden; state Exp; branches; next ; 1.21.2.1 date 97.11.06.07.01.19; author mellon; state Exp; branches; next ; 1.15.6.1 date 97.01.26.04.57.39; author rat; state Exp; branches; next 1.15.6.2; 1.15.6.2 date 97.03.04.15.18.16; author mycroft; state Exp; branches; next ; 1.1.1.1 date 93.03.21.09.45.37; author cgd; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 94.05.11.17.02.26; author jtc; state Exp; branches; next ; desc @@ 1.259 log @ Remove an ancient incorrect notion which somehow survived intact for ages. "$@@" is (as it is in double quotes) not subject to field splitting. "$@@" generates (potentially) multiple words, but field splitting has nothing to do with it. While here, rename the section from "White Space Splitting (Field Splitting)" to simply be "Field Splitting" as white space is only relevant if it happens to occur in IFS (which is the default case, but IFS can be anything, and isn't required to contain any white space at all). @ text @.\" $NetBSD: sh.1,v 1.258 2023/10/12 01:45:07 uwe Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Kenneth Almquist. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @@(#)sh.1 8.6 (Berkeley) 5/4/95 .\" .Dd December 9, 2022 .Dt SH 1 .\" everything except c o and s (keep them ordered) .ds flags abCEeFfhIiLlmnpquVvXx .Os .Sh NAME .Nm sh .Nd command interpreter (shell) .Sh SYNOPSIS .Nm .Bk -words .Op Fl \*[flags] .Op Cm +\*[flags] .Ek .Bk -words .Op Fl o Ar option_name .Op Cm +o Ar option_name .Ek .Bk -words .Op Ar command_file Op Ar argument ... .Ek .Nm .Fl c .Bk -words .Op Fl s .Op Fl \*[flags] .Op Cm +\*[flags] .Ek .Bk -words .Op Fl o Ar option_name .Op Cm +o Ar option_name .Ek .Bk -words .Ar command_string .Op Ar command_name Op Ar argument ... .Ek .Nm .Fl s .Bk -words .Op Fl \*[flags] .Op Cm +\*[flags] .Ek .Bk -words .Op Fl o Ar option_name .Op Cm +o Ar option_name .Ek .Bk -words .Op Ar argument ... .Ek .Sh DESCRIPTION .Nm is the standard command interpreter for the system. It is a re-implementation and extension of the Bourne shell. This version has many features which make it appear similar in some respects to the Korn shell, but it is not a Korn shell clone (see .Xr ksh 1 ) . This man page is not intended to be a tutorial or a complete specification of the shell. .Ss Overview The shell is a command that reads lines from either a file or the terminal, interprets them, and generally executes other commands. A shell is the program that is running when a user logs into the system. (Users can select which shell is executed for them at login with the .Xr chsh 1 command). The shell implements a language that has flow control constructs, a macro facility that provides a variety of features in addition to data storage, along with built in history and line editing capabilities. It incorporates many features to aid interactive use and has the advantage that the interpretative language is common to both interactive and non-interactive use (shell scripts). That is, commands can be typed directly to the running shell or can be put into a file and the file can be executed directly by the shell. .Ss Invocation If no arguments are present and if the standard input, and standard error output, of the shell are connected to a terminal (or terminals, or if the .Fl i flag is set), and the .Fl c option is not present, the shell is considered an interactive shell. An interactive shell generally prompts before each command and handles programming and command errors differently (as described below). When first starting, if neither the .Fl l nor .Cm \&+l options were given on the command line, the shell inspects argument 0, and if it begins with a dash .Sq \- , or if the .Fl l option was given, the shell is also considered a login shell. Beginning argument 0 with a dash is normally done automatically by the system when the user first logs in. A login shell first reads commands (as if by using the .Ql \&. command) from the files .Pa /etc/profile and .Pa .profile in the user's home directory .Pq Li \&$HOME , if they exist. If the environment variable .Ev ENV is set on entry to a shell, or is set in the .Pa .profile of a login shell, and either the shell is interactive, or the .Cm posix option is not set, the shell then performs parameter and arithmetic expansion on the value of .Ev ENV , (these are described later) and if no errors occurred, then reads commands from the file name that results. Note that no error messages result from these expansions, to verify that .Ev ENV is correct, as desired, use: .Dl eval printf '%s\e\en' \*q${ENV}\*q Otherwise if .Ev ENV appears to contain a command substitution, which is never performed here, or if there were no expansions to expand, the value of .Ev ENV is used as the file name. .Pp Therefore, a user should place commands that are to be executed only at login time in the .Pa .profile file, and commands that are executed for every shell inside the .Ev ENV file. To set the .Ev ENV variable to some file, place the following line in your .Pa .profile of your home directory .Pp .Dl ENV=$HOME/.shinit; export ENV .Pp substituting for .Pa .shinit any filename you wish. Since the .Ev ENV file can be read for every invocation of the shell, including shell scripts and non-interactive shells, the following paradigm is useful for restricting commands in the .Ev ENV file to interactive invocations. Place commands within the .Dq Ic case and .Dq Ic esac below (these commands are described later): .Bd -literal -offset indent case $- in *i*) # commands for interactive use only ... esac .Ed .Pp If command line arguments besides the options have been specified, and neither .Fl c nor .Fl s was given, then the shell treats the first argument as the name of a file from which to read commands (a shell script). This also becomes .Li $0 and the remaining arguments are set as the positional parameters of the shell .Li ( $1 , $2 , etc). Otherwise, if .Fl c was given, then the first argument, which must exist, is taken to be a string of .Nm commands to execute. Then if any additional arguments follow the command string, those arguments become .Li $0 , $1 , \&... Otherwise, if additional arguments were given (which implies that .Fl s was set) those arguments become .Li $1 , $2 , \&... If .Li $0 has not been set by the preceding processing, it will be set to .Va argv\^ Ns [ 0 ] as passed to the shell, which will usually be the name of the shell itself. If .Fl s was given, or if neither .Fl c nor any additional (non-option) arguments were present, the shell reads commands from its standard input. .\" .\" .Ss Argument List Processing .\" Currently, all of the single letter options that can meaningfully be set using the .Ic set built-in, have a corresponding name that can be used as an argument to the .Fl o option. The .Ic set Fl o name is provided next to the single letter option in the description below. Some options have only a long name, and are used with .Fl o or .Cm +o only, either on the command line, or with the .Ic set built-in command. Those are listed in the table below after the options with a one letter, flag, equivalent. .Pp Other options described are for the command line only. Specifying using a dash (or minus) .Dq Cm \- turns the option on, while using a plus .Dq Cm + disables the option. This may seem counter-intuitive, but is in line with the common practice where .Ic cmd Fl x runs .Ic cmd with the .Sq x option set. .Pp The following options can be set from the command line and, unless otherwise stated, with the .Ic set built-in (described later). .\" .\" strlen("quietprofile") == strlen("local_lineno"): pick the latter .\" to give the indent as the _ in local_lineno, and the fi ligature in .\" quietprofile combine to make "local_lineno' slightly wider when printed .\" (in italics) in a variable width font. .Bl -tag -width ".Fl L Em local_lineno" -offset indent .\" .It Fl a Em allexport Automatically export any variable to which a value is assigned while this flag is set, unless the variable has been marked as not for export. .It Fl b Em notify Enable asynchronous notification of background job completion. (Not implemented.) .It Fl C Em noclobber Don't overwrite existing files with .Dq > . .It Fl c Read commands from the .Ar command_string operand instead of, or in addition to, from the standard input. Special parameter .Dv 0 \" $0 (comments like this for searching sources only) will be set from the .Ar command_name operand if given, and the positional parameters .Dv ( 1 , 2 , etc.) set from the remaining argument operands, if any. .Fl c is only available at invocation, it cannot be .Ic set , and there is no form using .Dq Cm \&+ . .It Fl E Em emacs Enable the built-in emacs style command line editor (disables .Fl V if it had been set). (See the .Sx Command Line Editing section below.) .It Fl e Em errexit If not interactive, exit immediately if any untested command fails. If interactive, and an untested command fails, cease all processing of the current command and return to prompt for a new command. The exit status of a command is considered to be explicitly tested if the command is used to control an .Ic if , .Ic elif , .Ic while , or .Ic until , or if the command is the left hand operand of an .Dq && or .Dq || operator, or if it is a pipeline (or simple command) preceded by the .Dq \&! operator. With pipelines, only the status of the entire pipeline (indicated by the last command it contains) is tested when .Fl e is set to determine if the shell should exit. .It Fl F Em fork Cause the shell to always use .Xr fork 2 instead of attempting .Xr vfork 2 when it needs to create a new process. This should normally have no visible effect, but can slow execution. The .Nm can be compiled to always use .Xr fork 2 in which case altering the .Fl F flag has no effect. .It Fl f Em noglob Disable pathname expansion. .It Fl h Em trackall Functions defined while this option is set will have paths bound to commands to be executed by the function at the time of the definition. When off when a function is defined, the file system is searched for commands each time the function is invoked. (Obsolete and not implemented.) .It Fl I Em ignoreeof Ignore EOFs from input when interactive. (After a large number of consecutive EOFs the shell will exit anyway.) .It Fl i Em interactive Force the shell to behave interactively. If not set on the command line, this option is set automatically at shell startup if the shell is reading from standard input (no .Fl c , or .Ar command_file given at invocation of .Nm ) , and standard input and standard error refer to terminal type devices. .It Fl L Em local_lineno When set, before a function is defined, causes the variable .Dv LINENO when used within the function, to refer to the line number defined such that first line of the function is line 1. When reset, .Dv LINENO in a function refers to the line number within the file within which the definition of the function occurs. This option defaults to .Dq on in this shell. For more details see the section .Sx LINENO below. .It Fl l Em login When set on the command line, the shell will be considered a login shell. When reset on the command line .Po Cm \&+l or .Cm \&+o Em login Pc , the shell will not be considered a login shell, even if the command name parameter .Po Va argv[0] Pc begins with a dash .Pq Sq \- . See .Sx Invocation for the effects of this. Changing the value of this option while the shell is running has no effect. .It Fl m Em monitor Turn on job control (set automatically at shell startup, if not mentioned on the command line, when interactive). .It Fl n Em noexec Read and parse commands, but do not execute them. This is useful for checking the syntax of shell scripts. If .Fl n becomes set in an interactive shell, it will automatically be cleared just before the next time the command line prompt .Pq Ev PS1 is written. .It Fl p Em nopriv Do not attempt to reset effective UID if it does not match UID. The same applies to effective and real GIDs. This is not set by default to help avoid incorrect usage by setuid root programs via .Xr system 3 or .Xr popen 3 . This option is effective only when set on the command line, but can be reset to drop privileges, once, at any time. If .Fl p is cleared, those privileges can never be regained, however much the .Fl p option is manipulated. .It Fl q Em quietprofile If the .Fl v or .Fl x options have been set, temporarily disable them before reading initialization files, these being .Pa /etc/profile , .Pa .profile , and the file specified by the .Ev ENV environment variable. .It Fl s Em stdin Read commands from standard input (set automatically if neither .Fl c nor file arguments are present). If after processing a command_string with the .Fl c option, the shell has not exited, and the .Fl s option is set, it will continue reading more commands from standard input. This option has no effect when set or reset after the shell has already started reading from the command_file, or from standard input. Note that the .Fl s flag being set does not, of itself, cause the shell to be interactive. .It Fl u Em nounset Write a message to standard error when attempting to obtain a value from a variable that is not set, and if the shell is not interactive, exit immediately. For interactive shells, instead return immediately to the command prompt and read the next command. Note that expansions (described later, see .Sx Word Expansions below) using the .Sq \&+ , .Sq \&\- , .Sq \&= , or .Sq \&? operators test if the variable is set, before attempting to obtain its value, and hence are unaffected by .Fl u . .It Fl V Em vi Enable the built-in .Xr vi 1 command line editor (disables .Fl E if it had been set). (See the .Sx Command Line Editing section below.) .It Fl v Em verbose The shell writes its input to standard error as it is read. Perhaps occasionally useful for some debugging. .It Fl X Em xlock Cause output from the .Ic xtrace .Pq Fl x option to be sent to standard error as it exists when the .Fl X option is enabled (regardless of its previous state.) For example: .Bd -literal -compact set -X 2>/tmp/trace-file .Ed will arrange for tracing output to be sent to the file named, instead of wherever it was previously being sent, until the X option is set again, or cleared. .Pp Each change (set or clear) to .Fl X is also performed upon .Fl x , but not the converse. .It Fl x Em xtrace Write each command to standard error (preceded by the expanded value of .Li $PS4 ) before it is executed. Unless .Fl X is set, .Dq "standard error" means that which existed immediately before any redirections to be applied to the command are performed. Useful for debugging. .El .Pp The following options have no one letter variant, and are used only in conjunction with .Fl o or .Cm +o , either on the command line, or via the .Ic set built-in command. .Bl -tag -width ".Fl L Em local_lineno" -offset indent .It "\ \ " Em cdprint Make an interactive shell always print the new directory name when changed by the .Ic cd command. If the .Em posix option is set, this option also applies to non-interactive shells. However, .Em cdprint is an extension to POSIX, so these two options should rarely be set at the same time. .It "\ \ " Em nolog Prevent the entry of function definitions into the command history (see .Ic fc in the .Sx Built-ins section.) (Not implemented.) .It "\ \ " Em pipefail If set when a pipeline is created, the way the exit status of the pipeline is determined is altered. See .Sx Pipelines below for the details. .It "\ \ " Em posix Enables closer adherence to the POSIX shell standard. This option will default set at shell startup if the environment variable .Ev POSIXLY_CORRECT is present. That can be overridden (set or reset) by the .Fl o option on the command line. Currently this option controls whether (!posix) or not (posix) the file given by the .Ev ENV variable is read at startup by a non-interactive shell. It also controls whether file descriptors greater than 2 opened using the .Ic exec built-in command are passed on to utilities executed .Dq ( yes in posix mode), whether a colon (:) terminates the user name in tilde (~) expansions other than in assignment statements .Dq ( no in posix mode), the format of the output of the .Ic kill Fl l command, where posix mode causes the names of the signals be separated by either a single space or newline, and where otherwise sufficient spaces are inserted to generate nice looking columns, and whether the shell treats an empty brace-list compound statement as a syntax error (expected by POSIX) or permits it. Such statements .Dq "{\ }" can be useful when defining dummy functions. Lastly, in posix mode, only one .Dq \&! is permitted before a pipeline. .It "\ \ " Em promptcmds Allows command substitutions (as well as parameter and arithmetic expansions, which are always performed) upon the prompt strings .Ev PS1 , .Ev PS2 , and .Ev PS4 each time, before they are output. This option should not be set until after the prompts have been set (or verified) to avoid accidentally importing unwanted command substitutions from the environment. .It "\ \ " Em tabcomplete Enables filename completion in the command line editor. Typing a tab character will extend the current input word to match a filename. If more than one filename matches it is only extended to be the common prefix. Typing a second tab character will list all the matching names. One of the editing modes, either .Fl E or .Fl V , must be enabled for this to work. .El .Ss Lexical Structure The shell reads input in terms of lines from a file and breaks it up into words at whitespace (blanks and tabs), and at certain sequences of characters that are special to the shell called .Dq operators . There are two types of operators: control operators and redirection operators (their meaning is discussed later). The following is a list of operators: .Bl -ohang -offset indent .It "Control operators:" .Dl & && \&( \&) \&; ;; ;& \&| || .It "Redirection operators:" .Dl < > >| << >> <& >& <<- <> .El .Ss Quoting Quoting is used to remove the special meaning of certain characters or words to the shell, such as operators, whitespace, or keywords. There are four types of quoting: matched single quotes, matched double quotes, backslash, and dollar preceding matched single quotes (enhanced C style strings.) .Ss Backslash An unquoted backslash preserves the literal meaning of the following character, with the exception of .Aq newline . An unquoted backslash preceding a .Aq newline is treated as a line continuation, the two characters are simply removed. .Ss Single Quotes Enclosing characters in single quotes preserves the literal meaning of all the characters (except single quotes, making it impossible to put single quotes in a single-quoted string). .Ss Double Quotes Enclosing characters within double quotes preserves the literal meaning of all characters except dollar sign .Pq Li \&$ , backquote .Pq Li \&` , and backslash .Pq Li \e . The backslash inside double quotes is historically weird, and serves to quote only the following characters (and these not in all contexts): .Dl $ ` \*q \e , where a backslash newline is a line continuation as above. Otherwise it remains literal. .\" .\" .Ss Dollar Single Quotes ( Li \&$'...' ) .\" .Bd -filled -offset indent .Bf Em Note: this form of quoting is still somewhat experimental, and yet to be included in the POSIX standard. This implementation is based upon the current proposals for standardization, and is subject to change should the eventual adopted text differ. .Ef .Ed .Pp Enclosing characters in a matched pair of single quotes, with the first immediately preceded by an unquoted dollar sign .Pq Li \&$ provides a quoting mechanism similar to single quotes, except that within the sequence of characters, any backslash .Pq Li \e , is an escape character, which causes the following character to be treated specially. Only a subset of the characters that can occur in the string are defined after a backslash, others are reserved for future definition, and currently generate a syntax error if used. The escape sequences are modeled after the similar sequences in strings in the C programming language, with some extensions. .Pp The following characters are treated literally when following the escape character (backslash): .Dl \e \&' \(dq The sequence .Dq Li \e\e allows the escape character (backslash) to appear in the string literally. .Dq Li \e' allows a single quote character into the string, such an escaped single quote does not terminate the quoted string. .Dq Li \e\(dq is for compatibility with C strings, the double quote has no special meaning in a shell C-style string, and does not need to be escaped, but may be. .Pp A newline following the escape character is treated as a line continuation, like the same sequence in a double quoted string, or when not quoted \(en the two characters, the backslash escape and the newline, are removed from the input string. .Pp The following characters, when escaped, are converted in a manner similar to the way they would be in a string in the C language: .Dl a b e f n r t v An escaped .Sq a generates an alert (or .Sq BEL ) character, that is, control-G, or 0x07. In a similar way, .Sq b is backspace (0x08), .Sq e (an extension to C) is escape (0x1B), .Sq f is form feed (0x0C), .Sq n is newline (or line feed, 0x0A), .Sq r is return (0x0D), .Sq t is horizontal tab (0x09), and .Sq v is vertical tab (0x13). .Pp In addition to those there are 5 forms that need additional data, which is obtained from the subsequent characters. An escape .Pq Li \e followed by one, two or three, octal digits .Po So 0 Sc Ns \&.. Ns So 7 Sc Ns Pc is processed to form an 8 bit character value. If only one or two digits are present, the following character must be something other than an octal digit. It is safest to always use all 3 digits, with leading zeros if needed. If all three digits are present, the first must be one of .So 0 Sc Ns \&.. Ns So 3 Sc . .Pp An escape followed by .Sq x (lower case only) can be followed by one or two hexadecimal digits .Po So 0 Sc Ns \&.. Ns So 9 Sc , So A Sc Ns \&.. Ns So F Sc , or So a Sc Ns \&.. Ns So f Sc . Pc As with octal, if only one hex digit is present, the following character must be something other than a hex digit, so always giving 2 hex digits is best. However, unlike octal, it is unspecified in the standard how many hex digits can be consumed. This .Nm takes at most two, but other shells will continue consuming characters as long as they remain valid hex digits. Consequently, users should ensure that the character following the hex escape sequence is something other than a hex digit. One way to achieve this is to end the .Li $'...' string immediately after the final hex digit, and then, immediately start another, so .Dl \&$'\ex33'$'4...' always gives the character with value 0x33 .Pq Sq 3 , followed by the character .Sq 4 , whereas .Dl \&$'\ex334' in some other shells would be the hex value 0x334 (10, or more, bits). .Pp There are two escape sequences beginning with .Sq Li \eu or .Sq Li \eU . The former is followed by from 1 to 4 hex digits, the latter by from 1 to 8 hex digits. Leading zeros can be used to pad the sequences to the maximum permitted length, to avoid any possible ambiguity problem with the following character, and because there are some shells that insist on exactly 4 (or 8) hex digits. These sequences are evaluated to form the value of a Unicode code point, which is then encoded into UTF-8 form, and entered into the string. (The code point should be converted to the appropriate code point value for the corresponding character in the character set given by the current locale, or perhaps the locale in use when the shell was started, but is not... currently.) Not all values that are possible to write are valid, values that specify (known) invalid Unicode code points will be rejected, or simply produce .Sq \&? . .Pp Lastly, as another addition to what is available in C, the escape character (backslash), followed by .Sq c (lower case only) followed by one additional character, which must be an alphabetic character (a letter), or one of the following: .Dl \&@@ \&[ \&\e \&] \&^ \&_ \&? Other than .Sq Li \ec? the value obtained is the least significant 5 bits of the ASCII value of the character following the .Sq Li \ec escape sequence. That is what is commonly known as the .Dq control character obtained from the given character. The escape sequence .Sq Li \ec? yields the ASCII DEL character (0x7F). Note that to obtain the ASCII FS character (0x1C) this way, .Pq "that is control-\e" the trailing .Sq Li \e must be escaped itself, and so for this one case, the full escape sequence is .Dq Li \ec\e\e . The sequence .Dq Li \ec\e Ns Ar X\^ where .Sq Ar X\^ is some character other than .Sq Li \e is reserved for future use, its meaning is unspecified. In this .Nm an error is generated. .Pp If any of the preceding escape sequences generate the value .Sq \e0 (a NUL character) that character, and all that follow in the same .Li $'...' string, are omitted from the resulting word. .Pp After the .Li $'...' string has had any included escape sequences converted, it is treated as if it had been a single quoted string. .\" .\" .Ss Reserved Words .\" Reserved words are words that have special meaning to the shell and are recognized, if completely unquoted, at the beginning of a line, after a control operator, and where the syntax of a command specifically requires a reserved word. The following are reserved words: .Bl -column while while while while -offset indent .It Ic \&! Ta Ic \&{ Ta Ic \&} Ta Ic case .It Ic do Ta Ic done Ta Ic elif Ta Ic else .It Ic esac Ta Ic fi Ta Ic for Ta Ic if .It Ic in Ta Ic then Ta Ic until Ta Ic while .El .Pp Their meanings are discussed later. .\" .\" .Ss Aliases .\" An alias is a name and corresponding value set using the .Ic alias built-in command. Whenever a reserved word (see above) may occur, and after checking for reserved words, the shell checks the word to see if it matches an alias. If it does, the alias word is replaced by its value in the input stream, as if the value had been entered instead. For example, if there is an alias called .Dq lf with the value .Dq "ls -F" , then the input: .Pp .Dl lf foobar Aq return .Pp would become .Pp .Dl ls -F foobar Aq return .Pp Aliases provide a convenient way for naive users to create shorthands for commands without having to learn how to create functions with arguments. They can also be used to create lexically obscure code. This use is strongly discouraged. .\" .Ss Commands .\" The shell interprets the words it reads according to a language, the specification of which is outside the scope of this man page (refer to the BNF in the POSIX 1003.2 document). Essentially though, a line is read and if the first word of the line (or after a control operator) is not a reserved word, then the shell has recognized a simple command. Otherwise, a complex command or some other special construct may have been recognized. .\" .\" .Ss Simple Commands .\" If a simple command has been recognized, the shell performs the following actions: .Bl -enum -offset indent .It Leading words of the form .Dq Ar name Ns Li = Ns Ar value are stripped off, the value is expanded, as described below, and the results are assigned to the environment of the simple command. Redirection operators and their arguments (as described below) are stripped off and saved for processing in step 3 below. .It The remaining words are expanded as described in the .Sx Word Expansions section below. The first remaining word is considered the command name and the command is located. Any remaining words are considered the arguments of the command. If no command name resulted, then the .Dq Ar name Ns Li = Ns Ar value variable assignments recognized in item 1 affect the current shell, but are not automatically added to the environment (are not exported). .It Redirections are performed, from first to last, in the order given, as described in the next section. .El .\" .\" .Ss Redirections .\" Redirections are used to change where a command reads its input or sends its output. In general, redirections open, close, or duplicate an existing reference to a file. The overall format used for redirection is: .Pp .Dl Oo Ar n Oc Ns Va redir-op Ar file .Pp where .Va redir-op is one of the redirection operators mentioned previously. A list of the possible redirections, and their meanings, follows. .Pp The .Op Ar n is an optional number, as in .Sq Li 3 (not .Sq Li [3] ) , that refers to a file descriptor. If present it must occur unquoted, immediately before the redirection operator, with no intervening white space, and becomes a part of that operator. If not explicitly present, .Ar n will be 0 (standard input) or 1 (standard output) depending upon the redirection operator used. If file descriptor .Ar n was open prior to the redirection, its previous use is closed. .Pp All redirections have a single word .Ar file argument following the operator (white space is allowed between the redirection operator and .Ar file ) , though it is sometimes expressed as .Ar n2 . That argument is expanded (see .Sx "Word Expansions" below) using tilde expansion, parameter expansion, arithmetic expansion, command substitution and quote removal to produce the path name (or file descriptor) to be used. No field splitting or pathname expansion takes place. In the list below, where the .Ar file is given as .Ar n2 the result of the expansions must be a number which refers to a suitable open file descriptor. .Bl -tag -width aaabsfiles -offset indent .It Oo Ar n Oc Ns Ic > Ar file Redirect standard output (or .Ar n ) to .Ar file . .It Oo Ar n Oc Ns Ic >| Ar file The same, but override the .Fl C option. .It Oo Ar n Oc Ns Ic >> Ar file Append standard output (or .Ar n ) to .Ar file . .It Oo Ar n Oc Ns Ic < Ar file Redirect standard input (or .Ar n ) from .Ar file . .It Oo Ar n1 Oc Ns Ic <& Ar n2 Redirect standard input (or .Ar n1 ) from a duplicate of file descriptor .Ar n2 . .It Oo Ar n Oc Ns Ic <& \(mi Close standard input (or .Ar n ) . Note that the .Sq \&\(mi is minus sign (or hyphen) given literally or resulting from the expansion of .Ar file (or .Ar n2 ) for this format. When given literally there is usually no space between the redirection operator and the .Sq \&\(mi , though that is just a convention. .It Oo Ar n1 Oc Ns Ic >& Ar n2 Redirect standard output (or .Ar n1 ) to be a duplicate of .Ar n2 . .It Oo Ar n Oc Ns Ic >& \(mi Close standard output (or .Ar n ) . .It Oo Ar n Oc Ns Ic <> Ar file Open .Ar file for reading and writing on standard input (or .Ar n ) . .El .Pp The following redirection is often called a .Dq here-document . .Bd -unfilled -offset indent .Oo Ar n Oc Ns Ic << Ar delimiter .Li \&... here-doc-text ... .Ar delimiter .Ed .Pp The .Dq here-doc-text starts immediately after the next unquoted newline character following the here-document redirection operator. If there is more than one here-document redirection on the same line, then the text for the first (from left to right) is read first, and subsequent here-doc-text for later here-document redirections follows immediately after, until all such redirections have been processed. .Pp All the text on successive lines up to the delimiter, which must appear on a line by itself, with nothing other than an immediately following newline, is saved away and made available to the command on standard input, or file descriptor n if it is specified. If the delimiter as specified on the initial line is quoted, then the here-doc-text is treated literally; otherwise, the text is treated much like a double quoted string, except that .Sq Li \(dq characters have no special meaning, and are not escaped by .Sq Li \&\e , and is subjected to parameter expansion, command substitution, and arithmetic expansion as described in the .Sx Word Expansions section below. If the operator is .Ic <<- instead of .Ic << , then leading tabs in all lines in the here-doc-text, including before the end delimiter, are stripped. If the delimiter is not quoted, lines in here-doc-text that end with an unquoted .Li \e are joined to the following line, the .Li \e and following newline are simply removed while reading the here-document, which thus guarantees that neither of those lines can be the end delimiter. .Pp It is a syntax error for the end of the input file (or string) to be reached before the delimiter is encountered. .\" .\" .Ss Search and Execution .\" There are three types of commands: shell functions, built-in commands, and normal programs \(em and the command is searched for (by name) in that order. A command that contains a slash .Sq \&/ in its name is always a normal program. They each are executed in a different way. .Pp When a shell function is executed, all of the shell positional parameters (note: excluding .Li 0 , \" $0 which is a special, not positional, parameter, and remains unchanged) are set to the arguments of the shell function. The variables which are explicitly placed in the environment of the command (by placing assignments to them before the function name) are made local to the function and are set to the values given, and exported for the benefit of programs executed within the function. Then the command given in the function definition is executed. The positional parameters, and local variables, are restored to their original values when the command completes. This all occurs within the current shell, and the function can alter variables, or other settings, of the shell, but not the positional parameters nor their related special parameters. .Pp Shell built-ins are executed internally to the shell, without spawning a new process. .Pp Otherwise, if the command name doesn't match a function or built-in, the command is searched for as a normal program in the file system (as described in the next section). When a normal program is executed, the shell runs the program, passing the arguments and the environment to the program. If the program is not a normal executable file, and if it does not begin with the .Dq magic number whose ASCII representation is .Dq Li "#!" , so .Xr execve 2 returns .Er ENOEXEC then) the shell will interpret the program in a sub-shell. The child shell will reinitialize itself in this case, so that the effect will be as if a new shell had been invoked to handle the ad-hoc shell script, except that the location of hashed commands located in the parent shell will be remembered by the child. .Pp Note that previous versions of this document and the source code itself misleadingly and sporadically refer to a shell script without a magic number as a .Dq shell procedure . .\" .\" .Ss Path Search .\" When locating a command, command names containing a slash .Pq Sq \&/ are simply executed without performing any searches. .Pp If there is no slash in the name, the shell first looks to see if it is a special built-in command, if not it looks to see if there is a shell function by that name. If that fails it looks for an ordinary built-in command. If a none of these searches located the command the shell searches each entry in .Ev PATH in turn for the command. The value of the .Ev PATH variable should be a series of entries separated by colons. Each entry consists of a directory name. The current directory may be indicated implicitly by an empty directory name, or explicitly by a single period. If a directory searched contains an executable file with the same name as the command given, the search terminates, and that program is executed. .Ss Command Exit Status Each command has an exit status that can influence the behavior of other shell commands. The paradigm is that a command exits with zero in normal cases, or to indicate success, and non-zero for failure, error, or a false indication. The man page for each command should indicate the various exit codes and what they mean. Additionally, the built-in commands return exit codes, as does an executed shell function. .Pp If a command consists entirely of variable assignments then the exit status of the command is that of the last command substitution if any, otherwise 0. .Pp If redirections are present, and any fail to be correctly performed, any command present is not executed, and an exit status of 2 is returned. .Ss Complex Commands Complex commands are combinations of simple commands with control operators or reserved words, together creating a larger complex command. Overall, a shell program is a: .Bl -tag -width XpipelineX .It list Which is a sequence of one or more AND-OR lists. .It "AND-OR list" is a sequence of one or more pipelines. .It pipeline is a sequence of one or more commands. .It command is one of a simple command, a compound command, or a function definition. .It "simple command" has been explained above, and is the basic building block. .It "compound command" provides mechanisms to group lists to achieve different effects. .It "function definition" allows new simple commands to be created as groupings of existing commands. .El .Pp Unless otherwise stated, the exit status of a list is that of the last simple command executed by the list. .\" .\" .Ss Pipelines .\" A pipeline is a sequence of one or more commands separated by the control operator .Sq Ic \(ba , and optionally preceded by the .Dq Ic \&! reserved word. Note that .Sq Ic \(ba is an operator, and so is recognized anywhere it appears unquoted, it does not require surrounding white space or other syntax elements. On the other hand .Dq Ic \&! being a reserved word, must be separated from adjacent words by white space (or other operators, perhaps redirects) and is only recognized as the reserved word when it appears in a command word position (such as at the beginning of a pipeline.) .Pp The standard output of all but the last command in the sequence is connected to the standard input of the next command. The standard output of the last command is inherited from the shell, as usual, as is the standard input of the first command. .Pp The format for a pipeline is: .Pp .Dl [!] command1 Op Li \&| command2 No ... .Pp The standard output of command1 is connected to the standard input of command2. The standard input, standard output, or both of each command is considered to be assigned by the pipeline before any redirection specified by redirection operators that are part of the command are performed. .Pp If the pipeline is not in the background (discussed later), the shell waits for all commands to complete. .Pp The commands in a pipeline can either be simple commands, or one of the compound commands described below. The simplest case of a pipeline is a single simple command. .Pp If the .Ic pipefail option was set when a pipeline was started, the pipeline status is the status of the last (lexically last, i.e.: rightmost) command in the pipeline to exit with non-zero exit status, or zero, if, and only if, all commands in the pipeline exited with a status of zero. If the .Ic pipefail option was not set, which is the default state, the pipeline status is the exit status of the last (rightmost) command in the pipeline, and the exit status of any other commands in the pipeline is ignored. .Pp If the reserved word .Dq Ic \&! precedes the pipeline, the exit status becomes the logical NOT of the pipeline status as determined above. That is, if the pipeline status is zero, the exit status is 1; if the pipeline status is other than zero, the exit status is zero. If there is no .Dq Ic \&! reserved word, the pipeline status becomes the exit status. .Pp Because pipeline assignment of standard input or standard output or both takes place before redirection, it can be modified by redirection. For example: .Pp .Dl $ command1 2>&1 \&| command2 .Pp sends both the standard output and standard error of command1 to the standard input of command2. .Pp Note that unlike some other shells, each process in the pipeline is a child of the invoking shell, except in the case where the pipeline is a single simple command (no .Sq Ic \(ba characters appear.) .Pp A pipeline is a simple case of an AND-OR-list (described below.) A .Li \&; or .Aq newline terminator causes the preceding pipeline, or more generally, the preceding AND-OR-list to be executed sequentially; that is, the shell executes the commands, and waits for them to finish before proceeding to following commands. An .Li \&& terminator causes asynchronous (background) execution of the preceding AND-OR-list (see the next paragraph below). The exit status of an asynchronous AND-OR-list is zero. The actual status of the commands, after they have completed, can be obtained using the .Ic wait built-in command described later. .\" .\" .Ss Background Commands \(em Ic \&& .\" If a command, pipeline, or AND-OR-list is terminated by the control operator ampersand .Pq Li \&& , the shell executes the command asynchronously \(em that is, the shell does not wait for the command to finish before executing the next command. .Pp The format for running a command in background is: .Pp .Dl command1 & Op Li command2 & No ... .Pp If the shell is not interactive, the standard input of an asynchronous command is set to .Pa /dev/null . The process identifier of the most recent command started in the background can be obtained from the value of the special parameter .Dq Dv \&! \" $! (see .Sx Special Parameters ) provided it is accessed before the next asynchronous command is started. .\" .\" .Ss Lists \(em Generally Speaking .\" A list is a sequence of one or more commands separated by newlines, semicolons, or ampersands, and optionally terminated by one of these three characters. A shell program, which includes the commands given to an interactive shell, is a list. Each command in such a list is executed when it is fully parsed. Another use of a list is as a complete-command, which is parsed in its entirety, and then later the commands in the list are executed only if there were no parsing errors. .Pp The commands in a list are executed in the order they are written. If command is followed by an ampersand, the shell starts the command and immediately proceeds to the next command; otherwise it waits for the command to terminate before proceeding to the next one. A newline is equivalent to a .Sq Li \&; when no other operator is present, and the command being input could syntactically correctly be terminated at the point where the newline is encountered, otherwise it is just whitespace. .\" .\" .Ss AND-OR Lists (Short-Circuit List Operators) .\" .Dq Li \&&& and .Dq Li \&|| are AND-OR list operators. After executing the commands that precede the .Dq Li \&&& the subsequent command is executed if and only if the exit status of the preceding command(s) is zero. .Dq Li \&|| is similar, but executes the subsequent command if and only if the exit status of the preceding command is nonzero. If a command is not executed, the exit status remains unchanged and the following AND-OR list operator (if any) uses that status. .Dq Li \&&& and .Dq Li \&|| both have the same priority. Note that these operators are left-associative, so .Dl true || echo bar && echo baz writes .Dq baz and nothing else. This is not the way it works in C. .\" .\" .Ss Flow-Control Constructs \(em Ic if , while , until , for , case .\" These commands are instances of compound commands. The syntax of the .Ic if command is .Bd -literal -offset indent .Ic if Ar list .Ic then Ar list .Ic [ elif Ar list .Ic then Ar list ] No ... .Ic [ else Ar list ] .Ic fi .Ed .Pp The first list is executed, and if the exit status of that list is zero, the list following the .Ic then is executed. Otherwise the list after an .Ic elif (if any) is executed and the process repeats. When no more .Ic elif reserved words, and accompanying lists, appear, the list after the .Ic else reserved word, if any, is executed. .Pp The syntax of the .Ic while command is .Bd -literal -offset indent .Ic while Ar list .Ic do Ar list .Ic done .Ed .Pp The two lists are executed repeatedly while the exit status of the first list is zero. The .Ic until command is similar, but has the word .Ic until in place of .Ic while , which causes it to repeat until the exit status of the first list is zero. .Pp The syntax of the .Ic for command is .Bd -literal -offset indent .Ic for Ar variable Op Ic in Ar word No ... .Ic do Ar list .Ic done .Ed .Pp The words are expanded, or .Li \*q$@@\*q if .Ic in (and the following words) is not present, and then the list is executed repeatedly with the variable set to each word in turn. If .Ic in appears after the variable, but no words are present, the list is not executed, and the exit status is zero. .Ic do and .Ic done may be replaced with .Sq Ic \&{ and .Sq Ic \&} , but doing so is non-standard and not recommended. .Pp The syntax of the .Ic break and .Ic continue commands is .Bd -literal -offset indent .Ic break Op Ar num .Ic continue Op Ar num .Ed .Pp .Ic break terminates the .Ar num innermost .Ic for , while , or .Ic until loops. .Ic continue breaks execution of the .Ar num\^ Ns -1 innermost .Ic for , while , or .Ic until loops, and then continues with the next iteration of the enclosing loop. These are implemented as special built-in commands. The parameter .Ar num , if given, must be an unsigned positive integer (greater than zero). If not given, 1 is used. .Pp The syntax of the .Ic case command is .Bd -literal -offset indent .Ic case Ar word Ic in .Oo Ic \&( Oc Ar pattern Ns Ic \&) Oo Ar list Oc Ic \&;& .Oo Ic \&( Oc Ar pattern Ns Ic \&) Oo Ar list Oc Ic \&;; .No \&... .Ic esac .Ed .Pp The pattern can actually be one or more patterns (see .Sx Shell Patterns described later), separated by .Dq \(or characters. .Pp .Ar word is expanded and matched against each .Ar pattern in turn, from first to last, with each pattern being expanded just before the match is attempted. When a match is found, pattern comparisons cease, and the associated .Ar list , if given, is evaluated. If the list is terminated with .Dq Ic \&;& execution then falls through to the following list, if any, without evaluating its pattern, or attempting a match. When a list terminated with .Dq Ic \&;; has been executed, or when .Ic esac is reached, execution of the .Ic case statement is complete. The exit status is that of the last command executed from the last list evaluated, if any, or zero otherwise. .\" .\" .Ss Grouping Commands Together .\" Commands may be grouped by writing either .Dl Ic \&( Ns Ar list Ns Ic \&) or .Dl Ic \&{ Ar list Ns Ic \&; \&} These also form compound commands. .Pp Note that while parentheses are operators, and do not require any extra syntax, braces are reserved words, so the opening brace must be followed by white space (or some other operator), and the closing brace must occur in a position where a new command word might otherwise appear. .Pp The first of these executes the commands in a sub-shell. Built-in commands grouped into a .Li \&( Ns Ar list Ns \&) will not affect the current shell. The second form does not fork another shell so is slightly more efficient, and allows for commands which do affect the current shell. Grouping commands together this way allows you to redirect their output as though they were one program: .Bd -literal -offset indent { echo -n \*qhello \*q ; echo \*qworld\*q ; } > greeting .Ed .Pp Note that .Dq Ic } must follow a control operator (here, .Dq Ic \&; ) so that it is recognized as a reserved word and not as another command argument. .\" .\" .Ss Functions .\" The syntax of a function definition is .Pp .Dl Ar name Ns Ic \&() Ar command Op Ar redirect No ... .Pp A function definition is an executable statement; when executed it installs a function named .Ar name and returns an exit status of zero. To be portable, and standards compliant, the name must use the same syntax as a variable name, (see .Sx "Variables and Parameters" below). As an extension, this shell allows almost all characters in .Ar name .Po the exception is slash .Pq Sq \&/ as there is no way to invoke a function with a name containing a slash .Pc . Including quoting, whitespace, and operator characters requires that the word be quoted. The .Ar name is subject to quote removal, but no other expansions. Because of implementation issues, unquoted dollar signs .Pq Sq \&$ and backquotes .Pq Sq \&` are prohibited, but can be included in a function name by use of quoting. .Pp The command is normally a list enclosed between .Dq { and .Dq } . The standard syntax also allows the command to be any of the other compound commands, including a sub-shell, all of which are supported. As an extension, this shell also allows a simple command (or even another function definition) to be used, though users should be aware this is non-standard syntax. This means that .Dl l() ls \*q$@@\*q works to make .Dq l an alternative name for the .Ic ls command. .Pp If the optional redirect, (see .Sx Redirections ) , which may be of any of the normal forms, is given, it is applied each time the function is called. This means that a simple .Dq Hello World function might be written (in the extended syntax) as: .Bd -literal -offset indent hello() cat < 0). The shell sets these initially to the values of its command line arguments that follow the name of the shell script. The .Ic set built-in can also be used to set or reset them, and .Ic shift can be used to manipulate the list. .Pp To refer to the 10th (and later) positional parameters, the form .Li \&${ Ns Ar n Ns Li \&} must be used. Without the braces, a digit following .Dq $ can only refer to one of the first 9 positional parameters, or the special parameter .Dv 0 . \" $0 The word .Dq Li $10 is treated identically to .Dq Li ${1}0 . .\" .\" .Ss Special Parameters .\" A special parameter is a parameter denoted by one of the following special characters. The value of the parameter is listed next to its character. .Bl -tag -width thinhyphena .It Dv * Expands to the positional parameters, starting from one. When the expansion occurs in a situation where field splitting is never performed, such as within a double-quoted string, it expands to a single field with the value of each parameter separated by the first character of the .Ev IFS variable (possibly nothing if .Ev IFS has a null value), or by a .Aq space if .Ev IFS is unset. .It Dv @@ \" $@@ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each positional parameter expands as a separate argument. If the expansion happens in other situations where field splitting is not performed, whether double quoted or not, the results are undefined. In most shells, including this one, .Dv \&$@@ is treated as .Dv \&$* in such a context, but this is not universally true. If there are no positional parameters, the expansion of @@ generates zero arguments, even when .Dv $@@ is double-quoted. What this basically means, for example, is if .Li $1 is .Dq abc and .Li $2 is .Dq def\ ghi , then .Li \*q$@@\*q expands to the two arguments: .Pp .Sm off .Dl \*q abc \*q \ \*q def\ ghi \*q .Sm on .It Dv # Expands to the number of positional parameters. .It Dv \&? Expands to the exit status of the most recent pipeline. .It Dv \- No (dash, hyphen, or minus) Expands to the current option flags (the single-letter option names concatenated into a string) as specified on invocation, by the set built-in command, or implicitly by the shell. .It Dv $ Expands to the process ID of the invoked shell. A sub-shell retains the same value of .Dv $ as its parent. .It Dv \&! Expands to the process ID of the most recent background command executed from the current shell. For a pipeline, the process ID is that of the last command in the pipeline. If no background commands have yet been started by the shell, then .Dq Dv \&! will be unset. Once set, the value of .Dq Dv \&! will be retained until another background command is started. .It Dv 0 No (zero) \" $0 Expands to the name of the shell or shell script. .El .\" .\" .Ss Word Expansions .\" This section describes the various expansions that are performed on words. Not all expansions are performed on every word, as explained later. .Pp Tilde expansions, parameter expansions, command substitutions, arithmetic expansions, and quote removals that occur within a single word expand to a single field. It is only field splitting or pathname expansion that can create multiple fields from a single word. The single exception to this rule is the expansion of the special parameter .Dv @@ \" $@@ within double quotes, as was described above. .Pp The order of word expansion is: .Bl -enum .It Tilde Expansion, Parameter Expansion, Command Substitution, Arithmetic Expansion (these all occur at the same time, and the result of any of these expansions is not rescanned for further instances of the expansion, or any of the others). .It Unless the .Ev IFS variable has an empty value, Field Splitting is performed on the text resulting from the expansions in step (1) except for Tilde Expansion. .It Pathname Expansion (unless set .Fl f is in effect). .It Quote Removal. .El .Pp The $ character is used to introduce parameter expansion, command substitution, or arithmetic evaluation. .Ss Tilde Expansion (substituting a user's home directory) A word beginning with an unquoted tilde character (~) is subjected to tilde expansion. Provided all of the subsequent characters in the word are unquoted up to an unquoted slash (/) or when in an assignment or not in posix mode, an unquoted colon (:), or if neither of those appear, the end of the word, they are treated as a user name and are replaced with the pathname of the named user's home directory. If the user name is missing (as in .Pa ~/foobar ) , the tilde is replaced with the value of the .Dv HOME variable (the current user's home directory). .Pp In variable assignments, an unquoted tilde immediately after the assignment operator (=), and each unquoted tilde immediately after an unquoted colon in the value to be assigned is also subject to tilde expansion as just stated. .\" .\" .Ss Parameter Expansion .\" The format for parameter expansion is as follows: .Pp .Dl ${ Ns Ar expression Ns Li } .Pp where .Ar expression consists of all characters until the matching .Sq Li } . Any .Sq Li } escaped by a backslash or within a quoted string, and characters in embedded arithmetic expansions, command substitutions, and variable expansions, are not examined in determining the matching .Sq Li } . .Pp The simplest form for parameter expansion is: .Pp .Dl ${ Ns Ar parameter Ns Li } .Pp The value, if any, of .Ar parameter is substituted. .Pp The parameter name or symbol can be enclosed in braces, which are optional in this simple case, except for positional parameters with more than one digit or when parameter is followed by a character that could be interpreted as part of the name. If a parameter expansion occurs inside double quotes: .Bl -enum .It pathname expansion is not performed on the results of the expansion; .It field splitting is not performed on the results of the expansion. Note that the special rules for .Dv @@ \" $@@ can result in multiple fields being produced, but this is not because of field-splitting. If unquoted, each field produced by .Dv $@@ \" $@@ is subject to field splitting. .El .Pp In addition, a parameter expansion where braces are used, can be modified by using one of the following formats. If the .Sq Ic \&: is omitted in the following modifiers, then the test in the expansion applies only to unset parameters, not null ones. .Bl -tag -width aaparameterwordaaaaa .It Li ${ Ns Ar parameter Ns Ic :- Ns Ar word Ns Li } .Sy Use Default Values. If .Ar parameter is unset or null, the expansion of .Ar word is substituted; otherwise, the value of .Ar parameter is substituted. .It Li ${ Ns Ar parameter Ns Ic := Ns Ar word Ns Li } .Sy Assign Default Values. If .Ar parameter is unset or null, the expansion of .Ar word is assigned to .Ar parameter . In all cases, the final value of .Ar parameter is substituted. Only variables, not positional parameters or special parameters, can be assigned in this way. .It Li ${ Ns Ar parameter Ns Ic :? Ns Oo Ar word\^ Oc Ns Li } .Sy Indicate Error if Null or Unset. If .Ar parameter is unset or null, the expansion of .Ar word (or a message indicating it is unset if .Ar word is omitted) is written to standard error and a non-interactive shell exits with a nonzero exit status. An interactive shell will not exit, but any associated command(s) will not be executed. If the .Ar parameter is set, its value is substituted. .It Li ${ Ns Ar parameter Ns Ic :+ Ns Ar word Ns Li } .Sy Use Alternative Value. If .Ar parameter is unset or null, null is substituted; otherwise, the expansion of .Ar word is substituted. The value of .Ar parameter .Em is not used in this expansion. .It Li ${ Ns Ic # Ns Ar parameter Ns Li } .Sy String Length. The length in characters of the value of .Ar parameter . .El .Pp The following four varieties of parameter expansion provide for substring processing. In each case, pattern matching notation (see .Sx Shell Patterns ) , rather than regular expression notation, is used to evaluate the patterns. If parameter is .Dv * or .Dv @@ , \" $@@ the result of the expansion is unspecified. Enclosing the full parameter expansion string in double quotes does not cause the following four varieties of pattern characters to be quoted, whereas quoting characters within the braces has this effect. .Bl -tag -width aaparameterwordaaaaa .It Li ${ Ns Ar parameter Ns Ic % Ns Ar word Ns Li } .Sy Remove Smallest Suffix Pattern. The .Ar word is expanded to produce a pattern. The parameter expansion then results in .Ar parameter , with the smallest portion of the suffix matched by the pattern deleted. If the .Ar word is to start with a .Sq Li \&% character, it must be quoted. .It Li ${ Ns Ar parameter Ns Ic %% Ns Ar word Ns Li } .Sy Remove Largest Suffix Pattern. The .Ar word is expanded to produce a pattern. The parameter expansion then results in .Ar parameter , with the largest portion of the suffix matched by the pattern deleted. The .Dq Ic %% pattern operator only produces different results from the .Dq Ic \&% operator when the pattern contains at least one unquoted .Sq Li \&* . .It Li ${ Ns Ar parameter Ns Ic \&# Ns Ar word Ns Li } .Sy Remove Smallest Prefix Pattern. The .Ar word is expanded to produce a pattern. The parameter expansion then results in .Ar parameter , with the smallest portion of the prefix matched by the pattern deleted. If the .Ar word is to start with a .Sq Li \&# character, it must be quoted. .It Li ${ Ns Ar parameter Ns Ic \&## Ns Ar word Ns Li } .Sy Remove Largest Prefix Pattern. The .Ar word is expanded to produce a pattern. The parameter expansion then results in .Ar parameter , with the largest portion of the prefix matched by the pattern deleted. This has the same relationship with the .Dq Ic \&# pattern operator as .Dq Ic %% has with .Dq Ic \&% . .El .\" .\" .Ss Command Substitution .\" Command substitution allows the output of a command to be substituted in place of the command (and surrounding syntax). Command substitution occurs when a word contains a command list enclosed as follows: .Pp .Dl Ic $( Ns Ar list Ns Ic \&) .Pp or the older .Pq Dq backquoted version, which is best avoided: .Pp .Dl Ic \&` Ns Ar list Ns Ns Ic \&` .Pp See the section .Sx Complex Commands above for the definition of .Ic list . .Pp The shell expands the command substitution by executing the .Ar list in a sub-shell environment and replacing the command substitution with the standard output of the .Ar list after removing any sequence of one or more .Ao newline Ac Ns s from the end of the substitution. (Embedded .Ao newline Ac Ns s before the end of the output are not removed; however, during field splitting, they may be used to separate fields .Pq "as spaces usually are" depending on the value of .Ev IFS and any quoting that is in effect.) .Pp Note that if a command substitution includes commands to be run in the background, the sub-shell running those commands will only wait for them to complete if an appropriate .Ic wait command is included in the command list. However, the shell in which the result of the command substitution will be used will wait for both the sub-shell to exit and for the file descriptor that was initially standard output for the command substitution sub-shell to be closed. In some circumstances this might not happen until all processes started by the command substitution have finished. .\" While the exit of the sub-shell closes its standard output, .\" any background process left running may still .\" have that file descriptor open. .\" This includes yet another sub-shell which might have been .\" (almost invisibly) created to wait for some other command to complete, .\" and even where the background command has had its .\" standard output redirected or closed, .\" the waiting sub-shell may still have it open. .\" Thus there is no guarantee that the result of a command substitution .\" will be available in the shell which is to use it before all of .\" the commands started by the command substitution have completed, .\" though careful coding can often avoid delays beyond the termination .\" of the command substitution sub-shell. .\" .Pp .\" For example, assuming a script were to contain the following .\" code (which could be done better other ways, attempting .\" this kind of trickery is not recommended): .\" .Bd -literal -offset indent .\" if [ "$( printf "Ready? " >&2; read ans; printf "${ans}"; .\" { sleep 120 >/dev/null && kill $$ >/dev/null 2>&1; }& )" = go ] .\" then .\" printf Working... .\" # more code .\" fi .\" .Ed .\" .Pp .\" the .\" .Dq Working... .\" output will not be printed, and code that follows will never be executed. .\" Nor will anything later in the script .\" .Po .\" unless .\" .Dv SIGTERM .\" is trapped or ignored .\" .Pc . .\" .Pp .\" The intent is to prompt the user, wait for the user to .\" answer, then if the answer was .\" .Dq go .\" do the appropriate work, but set a 2 minute time limit .\" on completing that work. .\" If the work is not done by then, kill the shell doing it. .\" .Pp .\" It will usually not work as written, as while the 2 minute .\" .Sq sleep .\" has its standard output redirected, as does the .\" .Sq kill .\" that follows (which also redirects standard error, .\" so the user would not see an error if the work were .\" completed and there was no parent process left to kill); .\" the sub-shell waiting for the .\" .Sq sleep .\" to finish successfully, so it can start the .\" .Sq kill , .\" does not. .\" It waits, with standard output still open, .\" for the 2 minutes until the sleep is done, .\" even though the kill is not going to need that file descriptor, .\" and there is nothing else which could. .\" The command substitution does not complete until after .\" the kill has executed and the background sub-shell .\" finishes \(en at which time the shell running it is .\" presumably dead. .\" .Pp .\" Rewriting the background sub-shell part of that as .\" .Dl "{ sleep 120 && kill $$ 2>&1; } >/dev/null &" .\" would allow this .\" .Nm .\" to perform as expected, but that is not guaranteed, .\" not all shells would behave as planned. .\" It is advised to avoid starting background processes .\" from within a command substitution. .\" .\" .Ss Arithmetic Expansion .\" Arithmetic expansion provides a mechanism for evaluating an arithmetic expression and substituting its value. The format for arithmetic expansion is as follows: .Pp .Dl Ic $(( Ns Ar expression Ns Ic \&)) .Pp The expression in an arithmetic expansion is treated as if it were in double quotes, except that a double quote character inside the expression is just a normal character (it quotes nothing.) The shell expands all tokens in the expression for parameter expansion, command substitution, and quote removal (the only quoting character is the backslash .Sq \&\e , and only when followed by another .Sq \&\e , a dollar sign .Sq \&$ , a backquote .Sq \&` or a newline.) .Pp Next, the shell evaluates the expanded result as an arithmetic expression and substitutes the calculated value of that expression. .Pp Arithmetic expressions use a syntax similar to that of the C language, and are evaluated using the .Ql intmax_t data type (this is an extension to POSIX, which requires only .Ql long arithmetic.) Shell variables may be referenced by name inside an arithmetic expression, without needing a .Dq \&$ sign. Variables that are not set, or which have an empty (null string) value, used this way evaluate as zero (that is, .Dq x in arithmetic, as an R-Value, is evaluated as .Dq ${x:-0} ) unless the .Nm .Fl u flag is set, in which case a reference to an unset variable is an error. Note that unset variables used in the ${var} form expand to a null string, which might result in syntax errors. Referencing the value of a variable which is not numeric is an error. .Pp All of the C expression operators applicable to integers are supported, and operate as they would in a C expression. Use white space, or parentheses, to disambiguate confusing syntax, otherwise, as in C, the longest sequence of consecutive characters which make a valid token (operator, variable name, or number) is taken to be that token, even if the token designated cannot be used and a different interpretation could produce a successful parse. This means, as an example, that .Dq a+++++b is parsed as the gibberish sequence .Dq "a ++ ++ + b" , rather than as the valid alternative .Dq "a ++ + ++ b" . Similarly, separate the .Sq \&, operator from numbers with white space to avoid the possibility of confusion with the decimal indicator in some locales (though fractional, or floating-point, numbers are not supported in this implementation.) .Pp It should not be necessary to state that the C operators which operate on, or produce, pointer types, are not supported. Those include unary .Dq \&* and .Dq \&& and the struct and array referencing binary operators: .Dq \&. , .Dq \&-> and .Dq \&[ . .\" .\" .Ss Field Splitting .\" After parameter expansion, command substitution, and arithmetic expansion the shell scans the results of expansions and substitutions that did not occur in double quotes, for field splitting and multiple fields can result. .Pp The shell treats each character of the .Ev IFS as a delimiter and uses the delimiters to split the results of parameter expansion and command substitution into fields. .Pp Non-whitespace characters in .Ev IFS are treated strictly as parameter separators. So adjacent non-whitespace .Ev IFS characters will produce empty parameters. On the other hand, any sequence of whitespace characters that occur in .Ev IFS (known as .Ev IFS whitespace) can occur, leading and trailing .Ev IFS whitespace, and any .Ev IFS whitespace surrounding a non whitespace .Ev IFS delimiter, is removed. Any sequence of .Ev IFS whitespace characters without a non-whitespace .Ev IFS delimiter acts as a single field separator. .Pp If .Ev IFS is unset it is assumed to contain space, tab, and newline, all of which are .Ev IFS whitespace characters. If .Ev IFS is set to a null string, there are no delimiters, and no field splitting occurs. .Ss Pathname Expansion (File Name Generation) Unless the .Fl f flag is set, file name generation is performed after word splitting is complete. Each word is viewed as a series of patterns, separated by slashes. The process of expansion replaces the word with the names of all existing files whose names can be formed by replacing each pattern with a string that matches the specified pattern. There are two restrictions on this: first, a pattern cannot match a string containing a slash, and second, a pattern cannot match a string starting with a period unless the first character of the pattern is a period. The next section describes the patterns used for both Pathname Expansion and the .Ic case command. .Ss Shell Patterns A pattern consists of normal characters, which match themselves, and meta-characters. The meta-characters are .Dq \&! , .Dq * , .Dq \&? , and .Dq \&[ . These characters lose their special meanings if they are quoted. When command or variable substitution is performed and the dollar sign or backquotes are not double-quoted, the value of the variable or the output of the command is scanned for these characters and they are turned into meta-characters. .Pp An asterisk .Pq Dq * matches any string of characters. A question mark .Pq Dq \&? matches any single character. A left bracket .Pq Dq \&[ introduces a character class. The end of the character class is indicated by a right bracket .Pq Dq \&] ; if this .Dq \&] is missing then the .Dq \&[ matches a .Dq \&[ rather than introducing a character class. A character class matches any of the characters between the square brackets. A named class of characters (see .Xr wctype 3 ) may be specified by surrounding the name with .Pq Dq [: and .Pq Dq :] . For example, .Pq Dq [[:alpha:]] is a shell pattern that matches a single letter. A range of characters may be specified using a minus sign .Pq Dq \(mi . The character class may be complemented by making an exclamation mark .Pq Dq \&! the first character of the character class. .Pp To include a .Dq \&] in a character class, make it the first character listed (after the .Dq \&! , if any). To include a .Dq \(mi , make it the first (after !) or last character listed. If both .Dq \&] and .Dq \(mi are to be included, the .Dq \&] must be first (after !) and the .Dq \(mi last, in the character class. .\" .\" .Ss Built-ins .\" This section lists the built-in commands which are built in because they need to perform some operation that can't be performed by a separate process. Or just because they traditionally are. In addition to these, there are several other commands that may be built in for efficiency (e.g. .Xr printf 1 , .Xr echo 1 , .Xr test 1 , etc). Most built-in commands will exit with status 2 if used incorrectly (bad options, excess or insufficient number of arguments, etc). Otherwise, unless stated differently, the built-in commands exit with status 0, unless some error occurs, which would be reported to standard error. .Bl -tag -width 5n -compact .Pp .It Ic \&: Op Ar arg ... A null command that returns a 0 (true) exit value. Any arguments or redirects are evaluated just as for any other command, then ignored. .\" .Pp .It Ic \&. Ar file The dot command reads and executes the commands from the specified .Ar file in the current shell environment. The file does not need to be executable and is looked up from the directories listed in the .Ev PATH variable if its name does not contain a directory separator .Pq Sq / . The .Ic return command (see below) can be used for a premature return from the sourced file. .Pp The POSIX standard has been unclear on how loop control keywords (break and continue) behave across a dot command boundary. This implementation allows them to control loops surrounding the dot command, but obviously such behavior should not be relied on. It is now permitted by the standard, but not required. .\" .Pp .It Ic alias Op Ar name Ns Op Li = Ns Ar string ... If .Ar name Ns Li = Ns Ar string is specified, the shell defines the alias .Ar name with value .Ar string . If just .Ar name is specified, the value of the alias .Ar name is printed. With no arguments, the .Ic alias built-in prints the names and values of all defined aliases (see .Ic unalias ) . .\" .Pp .It Ic bg Op Ar job ... Continue the specified jobs (or the current job if no jobs are given) in the background. .\" .Pp .It Ic command Oo Fl pVv Oc Ar command Op Ar arg ... Execute the specified command but ignore shell functions when searching for it. (This is useful when you have a shell function with the same name as a command.) .Bl -tag -width 5n .It Fl p search for command using a .Ev PATH that guarantees to find all the standard utilities, but not necessarily any others. .It Fl V Do not execute the .Ar command but search for the .Ar command and print the resolution of the command search. This is the same as the .Ic type built-in. .It Fl v Do not execute the .Ar command but search for the .Ar command and print the absolute pathname of utilities, the name for built-ins or the expansion of aliases. .El .\" .Pp .It Ic cd Oo Fl Pe Oc Op Ar directory Op Ar replace Switch to the specified directory (default .Ev $HOME ) . If .Ar replace is specified, then the new directory name is generated by replacing the first occurrence of the string .Ar directory in the current working directory name with .Ar replace . Otherwise if .Ar directory is .Sq Li - , then the current working directory is changed to the previous current working directory as set in .Ev OLDPWD . Otherwise if an entry for .Ev CDPATH appears in the environment of the .Ic cd command or the shell variable .Ev CDPATH is set and the .Ar directory name does not begin with a slash, and its first (or only) component isn't dot or dot dot, then the directories listed in .Ev CDPATH will be searched for the specified .Ar directory . The format of .Ev CDPATH is the same as that of .Ev PATH . .Pp The .Fl P option (which is the unalterable default in this .Nm ) instructs the shell to change to the directory specified (or determined) and if successful update .Ev PWD with the new physical directory path. That is the path name, not traversing any symbolic links, of the altered working directory of the shell. .Pp The .Fl e option alters the interpretation of the exit status. .Ic cd will exit with status 0 if successful. If the directory was successfully changed, but .Ev PWD was unable to be updated, .Ic cd will exit with status 1 if the .Fl e option was given, and status 0 otherwise. Upon any other error, including usage errors, and failing to successfully change directory, .Ic cd will exit with status 2. .Pp When the directory changes, and .Ev PWD is updated, the variable .Ev OLDPWD is set to the working directory .Po \&$ Ns Ev PWD Ns Pc as it was before the change. .Pp Some shells also support a .Fl L option, which instructs the shell to update .Ev PWD with the logical path using string manipulation, and then to change the current directory accordingly. This is not supported. .Pp In an interactive shell, or if the .Cm posix option is set, the .Ic cd command will print out the name of the directory that it actually switched to; .Po that is, the pathname passed to the successful .Xr chdir 2 .No system call Pc if this is different from the name that the user gave, or if the .Cm cdprint option is set. The destination may be different because a non-empty element of the .Ev CDPATH mechanism was used, .\" or because a symbolic link was crossed. XXX Definitively not (not even -L) or because the .Ar replace argument was used, or because the .Ar directory parameter was specified as .Dq \&\- . .\" .Pp .It Ic eval Ar string ... Concatenate all the .Ar string arguments with intervening spaces. Then parse and execute the resulting command. The exit status from .Ic eval is the exit status of the command executed, or 0 if there was none. .\" .Pp .It Ic exec Op Ar command Op Ar arg ... Unless .Ar command is omitted, the shell process is replaced with the specified program (which must be a real program, not a shell built-in or function). Any redirections on the .Ic exec command are marked as permanent, so that they are not undone when the .Ic exec command finishes. When the .Cm posix option is not set, file descriptors created via such redirections are marked close-on-exec (see .Xr open 2 .Dv O_CLOEXEC or .Xr fcntl 2 .Dv F_SETFD / .Dv FD_CLOEXEC ) , unless the descriptors refer to the standard input, output, or error (file descriptors 0, 1, 2). Traditionally Bourne-like shells (except .Xr ksh 1 ) , made those file descriptors available to exec'ed processes. To be assured the close-on-exec setting is off, redirect the descriptor to (or from) itself, either when invoking a command for which the descriptor is wanted open, or by using .Ic exec .Po perhaps the same .Ic exec .No as opened it, after the open Pc to leave the descriptor open in the shell and pass it to all commands invoked subsequently. Alternatively, see the .Ic fdflags command below, which can set, or clear, this, and other, file descriptor flags. .\" .Pp .It Ic exit Op Ar exitstatus Terminate the shell process. If .Ar exitstatus is given it is used as the exit status of the shell; otherwise the exit status of the preceding command (the current value of $?) is used. .\" .Pp .It Ic export Oo Fl nx Oc Ar name Ns Oo =value Oc ... .It Ic export Oo Fl x Oc Oo Fl p Oo Ar name ... Oc Oc .It Ic export Fl q Oo Fl x Oc Ar name ... With no options, but one or more names, the specified names are exported so that they will appear in the environment of subsequent commands. With .Fl n the specified names are un-exported. Variables can also be un-exported using the .Ic unset built in command. With .Fl x .Pq exclude the specified names are marked not to be exported, and any that had been exported, will be un-exported. Later attempts to export the variable will be refused. Note this does not prevent explicitly exporting a variable to a single command, script or function by preceding that command invocation by a variable assignment to that variable, provided the variable is not also read-only. That is .Bd -literal -offset indent export -x FOO # FOO will now not be able to be exported export FOO # this command will fail (non-fatally) .Ed But with .Bd -literal -offset indent -compact FOO=some_value my_command .Ed .Nm still passes the value .Pq Li FOO=some_value to .Li my_command through the environment. .Pp The shell allows the value of a variable to be set at the same time it is exported (or unexported, etc) by writing .Pp .Dl export [-nx] name=value .Pp Note that in such a usage, the .Dq name=value argument often needs to be quoted, more often than is required of an assignment statement, as, like with any other command, the command name and arguments are all subject to the various expansions, including filename expansion and field splitting, before the .Ic export command is invoked. With the default value for .Dv IFS : .Bd -unfilled -offset indent -compact X='a b c' export Y=$X .Ed the command invoked would be .Dl "export Y=a b c" exporting .Dv Y , with the value .Dq a and also exporting the variables named .Dq b and .Dq c , which is probably not as intended. .Pp With no arguments the export command lists the names of all set exported variables, or if .Fl x was given, all set variables marked not for export. With the .Fl p option specified, the output will be formatted suitably for non-interactive use, and unset variables are included. When .Fl p is given, variable names, but not values, may also be given, in which case output is limited to the variables named. .Pp With .Fl q and a list of variable names, the .Ic export command will exit with status 0 if all the named variables have been marked for export, or 1 if any are not so marked. If .Fl x is also given, the test is instead for variables marked not to be exported. .Pp Other than with .Fl q , the .Ic export built-in exits with status 0, unless an attempt is made to export a variable which has been marked as unavailable for export, in which cases it exits with status 1. In all cases if an invalid option, or option combination, is given, or an invalid variable name is present, .Ic export will write a message to the standard error output, and exit with a non-zero status. A non-interactive shell will terminate. .Pp Note that there is no restriction upon exporting, or un-exporting, read-only variables. The no-export flag can be reset by unsetting the variable and creating it again \(en provided the variable is not also read-only. .\" .Pp .It Ic fc Oo Fl e Ar editor Oc Op Ar first Op Ar last .It Ic fc Fl l Oo Fl nr Oc Op Ar first Op Ar last .It Ic fc Fl s Oo Ar old=new Oc Op Ar first The .Ic fc built-in lists, or edits and re-executes, commands previously entered to an interactive shell. .Bl -tag -width 5n .It Fl e Ar editor Use the editor named by .Ar editor to edit the commands. The .Ar editor string is a command name, subject to search via the .Ev PATH variable. The value in the .Ev FCEDIT variable is used as a default when .Fl e is not specified. If .Ev FCEDIT is null or unset, the value of the .Ev EDITOR variable is used. If .Ev EDITOR is null or unset, .Xr ed 1 is used as the editor. .It Fl l No (ell) List the commands rather than invoking an editor on them. The commands are written in the sequence indicated by the first and last operands, as affected by .Fl r , with each command preceded by the command number. .It Fl n Suppress command numbers when listing with .Fl l . .It Fl r Reverse the order of the commands listed (with .Fl l ) or edited (with neither .Fl l nor .Fl s ) . .It Fl s Re-execute the command without invoking an editor. .It Ar first .It Ar last Select the commands to list or edit. The number of previous commands that can be accessed are determined by the value of the .Ev HISTSIZE variable. The value of .Ar first or .Ar last or both are one of the following: .Bl -tag -width 5n .It Oo Cm + Oc Ns Ar number A positive number representing a command number; command numbers can be displayed with the .Fl l option. .It Cm \- Ns Ar number A negative decimal number representing the command that was executed number of commands previously. For example, \-1 is the immediately previous command. .El .It Ar string A string indicating the most recently entered command that begins with that string. If the .Ar old Ns Li = Ns Ar new operand is not also specified with .Fl s , the string form of the first operand cannot contain an embedded equal sign. .El .Pp The following environment variables affect the execution of .Ic fc : .Bl -tag -width HISTSIZE .It Ev FCEDIT Name of the editor to use. .It Ev HISTSIZE The number of previous commands that are accessible. .El .\" .Pp .It Ic fg Op Ar job Move the specified job or the current job to the foreground. A foreground job can interact with the user via standard input, and receive signals from the terminal. .\" .Pp .It Ic fdflags Oo Fl v Oc Op Ar fd ... .It Ic fdflags Oo Fl v Oc Fl s Ar flags fd Op ... Get or set file descriptor flags. The .Fl v argument enables verbose printing, printing flags that are also off, and the flags of the file descriptor being set after setting. The .Fl s flag interprets the .Ar flags argument as a comma separated list of file descriptor flags, each preceded with a .Dq \(pl or a .Dq \(mi indicating to set or clear the respective flag. Valid flags are: .Cm append , .Cm async , .Cm sync , .Cm nonblock , .Cm fsync , .Cm dsync , .Cm rsync , .Cm direct , .Cm nosigpipe , and .Cm cloexec . Unique abbreviations of these names, of at least 2 characters, may be used on input. See .Xr fcntl 2 and .Xr open 2 for more information. .\" .Pp .It Ic getopts Ar optstring var The POSIX .Ic getopts command, not to be confused with the Bell Labs\[en]derived .Xr getopt 1 . .Pp The first argument should be a series of letters, each of which may be optionally followed by a colon (:) to indicate that the option requires an argument. The variable specified is set to the parsed option. .Pp The .Ic getopts command deprecates the older .Xr getopt 1 utility due to its handling of arguments containing whitespace. .Pp The .Ic getopts built-in may be used to obtain options and their arguments from a list of parameters. When invoked, .Ic getopts places the value of the next option from the option string in the list in the shell variable specified by .Ar var and its index in the shell variable .Ev OPTIND . When the shell is invoked, .Ev OPTIND is initialized to 1. For each option that requires an argument, the .Ic getopts built-in will place it in the shell variable .Ev OPTARG . If an option is not allowed for in the .Ar optstring , then .Ev OPTARG will be unset. .Pp .Ar optstring is a string of recognized option letters (see .Xr getopt 3 ) . If a letter is followed by a colon (:), the option is expected to have an argument which may or may not be separated from the option by whitespace. If an option character is not found where expected, .Ic getopts will set the variable .Ar var to .Sq Li \&? ; .Ic getopts will then unset .Ev OPTARG and write an error to standard error. .Pp By specifying a colon (:) as the first character of .Ar optstring , the error handling behavior changes: no errors will be written to standard error; unknown option characters will set .Ar var to .Sq Li \&? and set .Ev OPTARG to the unknown option character (instead of unset .Ev OPTARG Ns ); and missing option arguments will set .Ar var to .Sq Li \&: and set .Ev OPTARG to the option character with the missing argument. .Pp A nonzero value is returned when the last option is reached. If there are no remaining arguments, .Ic getopts will set .Ar var to the special option, .Dq Li \-\- , otherwise, it will set .Ar var to .Sq Li \&? . .Pp The following code fragment shows how one might process the arguments for a command that can take the options .Fl a and .Fl b , and the option .Fl c , which requires an argument. .Bd -literal -offset indent while getopts abc: f do case $f in a | b) flag=$f;; c) carg=$OPTARG;; \e?) echo $USAGE; exit 1;; esac done shift $((OPTIND - 1)) .Ed .Pp This code will accept any of the following as equivalent: .Bd -literal -offset indent cmd \-acarg file file cmd \-a \-c arg file file cmd \-carg -a file file cmd \-a \-carg \-\- file file .Ed .\" .Pp .It Ic hash Oo Fl befqrsuv Oc Op Ar command ... The shell maintains a hash table which remembers the locations and types of commands. With the .Fl r option given, the .Ic hash command begins by clearing all commands, except special built-in commands and functions, from this table. Commands, other than functions, are added to the table as described below, or as they are encountered through normal execution, or for functions, when they are defined. Functions are removed with the .Ic unset built-in command. Special built-in commands are added at shell startup, and never removed. Utilities can also be removed when .Ev PATH is altered. .Pp With no .Ar command arguments the .Ic hash command then prints out the contents of this table. Note that this is a hash table, the order of the contents is unpredictable, and meaningless. .Pp The .Fl b , .Fl f , .Fl s , and .Fl u options control which entries are printed. With .Fl f functions are printed; with .Fl b or .Fl s regular, or special, built-in commands are listed; and with .Fl u normal utilities (those commands found in the filesystem by searching .Ev PATH ) are printed. For compatibility with some older versions of the .Ic hash command, .Fl c is accepted as an alternative of .Fl u . .Pp Some normal command entries which have not been verified since the last .Ic cd command are marked with an asterisk; it is possible for these entries to be invalid. .Pp The .Fl v option causes more verbose output to be included, indicating the type of the command, rather than simply its name. For functions, the body of the function is included. .Pp If none of the above options is given, the default is to show normal commands only. With .Fl v and no other options, the whole table (all types) will be shown. .Pp Unless there is an error writing the output, the .Ic hash command will exit with status 0 in this usage. .Pp With .Ar command arguments, the .Ic hash command removes the specified commands from the hash table (unless they are functions or special built-in commands) and then locates and reinstalls them. With the .Fl v option, .Ic hash prints the locations of the commands as it finds them. The .Fl bfsu options control which types of commands will be affected. If any of those options is given, and a command found to already be in the hash table is not one of the designated types, that entry, and the .Ar command argument, will simply be silently skipped. If none of those flags is given, any command type can be affected. .Pp If a .Ar command is not located, then unless .Fl q was given, a .Dq not found error message will be printed. .Pp The .Fl e option implies .Fl q if that option was not given, and also causes the exit status of the .Ic hash command to ignore the unfound .Ar command . Otherwise if any .Ar command is not found, the .Ic hash command will exit with status 1. .Pp To allow a method to permit backwards compatibility with the way that the .Ic hash command worked before .Nx 10.0 , if both the .Fl e and .Fl q options are given, then an error message will be printed about .Ar command Ns No s unable to be found, but the exit status will remain 0. This is not considered useful. .\" .Pp .It Ic inputrc Ar file Read the .Ar file to set key bindings as defined by .Xr editrc 5 . .\" .Pp .It Ic jobid Oo Fl g Ns \&| Ns Fl j Ns \&| Ns Fl p Oc Op Ar job With no flags, print the process identifiers of the processes in the job. If the .Ar job argument is omitted, the current job is used. Any of the ways to select a job may be used for .Ar job , including the .Sq Li \&% forms, or the process id of the job leader .Po .Dq Li \&$! if the job was created in the background. .Pc .Pp If one of the flags is given, then instead of the list of process identifiers, the .Ic jobid command prints: .Bl -tag -width ".Fl g" .It Fl g the process group, if one was created for this job, or nothing otherwise (the job is in the same process group as the shell.) .It Fl j the job identifier (using .Dq Li \&% Ns Ar n notation, where .Ar n is a number) is printed. .It Fl p only the process id of the process group leader is printed. .El .Pp These flags are mutually exclusive. .Pp .Ic jobid exits with status 2 if there is an argument error, status 1, if with .Fl g the job had no separate process group, or with .Fl p there is no process group leader (should not happen), and otherwise exits with status 0. .\" .Pp .It Ic jobs Oo Fl l Ns \&| Ns Fl p Oc Op Ar job ... .It Ic jobs Fl Z Op Ar title Without .Ar job arguments, this command lists out all the background processes which are children of the current shell process. With .Ar job arguments, the listed jobs are shown instead. Without flags, the output contains the job identifier (see .Sx Job Control below), an indicator character if the job is the current or previous job, the current status of the job (running, suspended, or terminated successfully, unsuccessfully, or by a signal) and a (usually abbreviated) command string. .Pp With the .Fl l flag the output is in a longer form, with the process identifiers of each process (run from the top level, as in a pipeline), and the status of each process, rather than the job status. .Pp With the .Fl p flag, the output contains only the process identifier of the lead process (which is also the process group identifier). Note that this is not necessarily the same process identifier as reported in the special parameter .Dv \&! when a background job is started. .Pp With the .Fl Z flag, the process command line is set using .Xr setproctitle 3 . If .Ar title is omitted or a null string, .Xr setproctitle 3 is called with a .Dv NULL format. .Pp These options are mutually exclusive, the last specified is used. .Pp In an interactive shell, each job shown as completed in the output from the jobs command is implicitly waited for, and is removed from the jobs table, never to be seen again. In an interactive shell, when a background job terminates, the .Ic jobs command (with that job as an argument) is implicitly run just before outputting the next PS1 command prompt, after the job terminated. This indicates that the job finished, shows its status, and cleans up the job table entry for that job. Non-interactive shells need to execute .Ic wait commands to clean up terminated background jobs. .\" .Pp .It Ic local Oo Fl INx Oc Oo Ar variable | \- Oc ... Define local variables for a function. Local variables have their attributes, and values, as they were before the .Ic local declaration, restored when the function terminates. .Pp With the .Fl N flag, variables made local, are unset initially inside the function. Unless the .Fl x flag is also given, such variables are also unexported. The .Fl I flag, which is the default in this shell, causes the initial value and exported attribute of local variables to be inherited from the variable with the same name in the surrounding scope, if there is one. If there is not, the variable is initially unset, and not exported. The .Fl N and .Fl I flags are mutually exclusive, if both are given, the last specified applies. The read-only and unexportable attributes are always inherited, if a variable with the same name already exists. .Pp The .Fl x flag (lower case) causes the local variable to be exported, while the function runs, unless it has the unexportable attribute. This can also be accomplished by using the .Ic export command, giving the same .Ar variable names, after the .Ic local command. .Pp Making an existing read-only variable local is possible, but pointless. If an attempt is made to assign an initial value to such a variable, the .Ic local command fails, as does any later attempted assignment. If the .Ic readonly command is applied to a variable that has been declared local, the variable cannot be (further) modified within the function, or any other functions it calls, however when the function returns, the previous status (and value) of the variable is returned. .Pp Values may be given to local variables on the .Ic local command line in a similar fashion as used for .Ic export and .Ic readonly . These values are assigned immediately after the initialization described above. Note that any variable references on the command line will have been expanded before .Ic local is executed, so expressions like .Bd -unfilled -offset indent local -N X="${X}" .Ed .Pp are well defined, first $X is expanded, and then the command run is .Dl "local -N X='old-value-of-X'" See the description of the .Ic export built-in command for notes on why quoting the value is required. .Pp After arranging to preserve the old value and attributes, of .Dv X .Dq ( old-value-of X ) .Ic local unsets .Dv X , unexports it, and then assigns the .Dq old-value-of-X to .Ev X . .Pp The shell uses dynamic scoping, so that if you make the variable .Dv x local to function .Dv f , which then calls function .Dv g , references to the variable .Dv x made inside .Dv g will refer to the variable .Dv x declared inside .Dv f , not to the global variable named .Dv x . .Pp Another way to view this, is as if the shell just has one flat, global, namespace, in which all variables exist. The .Ic local command conceptually copies the variable(s) named to unnamed temporary variables, and when the function ends, copies them back again. All references to the variables reference the same global variables, but while the function is active, after the .Ic local command has run, the values and attributes of the variables might be altered, and later, when the function completes, be restored. .Pp Note that the positional parameters .Dv 1 , \" $1 .Dv 2 , \" $2 \&... (see .Sx Positional Parameters ) , and the special parameters .Dv \&# , \" $# .Dv \&* \" $* and .Dv \&@@ \" $@@ (see .Sx Special Parameters ) , are always made local in all functions, and are reset inside the function to represent the options and arguments passed to the function. Note that .Li $0 however retains the value it had outside the function, as do all the other special parameters. .Pp The only special parameter that can optionally be made local is .Dq Li \- . Making .Dq Li \- local causes any shell options that are changed via the set command inside the function to be restored to their original values when the function returns. If .Fl X option is altered after .Dq Li \- has been made local, then when the function returns, the previous destination for .Cm xtrace output (as of the time of the .Ic local command) will also be restored. If any of the shell's magic variables (those which return a value which may vary without the variable being explicitly altered, e.g.: .Dv SECONDS or .Dv HOSTNAME ) are made local in a function, they will lose their special properties when set within the function, including by the .Ic local command itself (if not to be set in the function, there is little point in making a variable local) but those properties will be restored when the function returns. .Pp It is an error to use .Ic local outside the scope of a function definition. When used inside a function, it exits with status 0, unless an undefined option is used, or an attempt is made to assign a value to a read-only variable. .Pp Note that either .Fl I or .Fl N should always be used, or variables made local should always be given a value, or explicitly unset, as the default behavior (inheriting the earlier value, or starting unset after .Ic local ) differs amongst shell implementations. Using .Dq Li local \&\- is an extension not implemented by most shells. .Pp See the section .Sx LINENO below for details of the effects of making the variable .Dv LINENO local. .\" .Pp .It Ic pwd Op Fl \&LP Print the current directory. If .Fl L is specified the cached value (initially set from .Ev PWD ) is checked to see if it refers to the current directory; if it does the value is printed. Otherwise the current directory name is found using .Xr getcwd 3 . .Pp The default is .Ic pwd .Fl L , but note that the built-in .Ic cd command doesn't support the .Fl L option and will cache (almost) the absolute path. If .Ic cd is changed (as unlikely as that is), .Ic pwd may be changed to default to .Ic pwd .Fl P . .Pp If the current directory is renamed and replaced by a symlink to the same directory, or the initial .Ev PWD value followed a symbolic link, then the cached value may not be the absolute path. .Pp The built-in command may differ from the program of the same name because the program will use .Ev PWD and the built-in uses a separately cached value. .\" .Pp .It Ic read Oo Fl d Ar delim Oc Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Op Ar ... The .Ar prompt is printed on standard error if the .Fl p option is specified and the standard input is a terminal. Then a record, terminated by the first character of .Ar delim if the .Fl d option was given, or a newline character otherwise, is read from the standard input. The ending delimiter is deleted from the record which is then split as described in the field splitting section of the .Sx Word Expansions section above. The pieces are assigned to the .Ar variable Ns s in order. If there are more pieces than variables, the remaining pieces (along with the characters in .Ev IFS that separated them) are all assigned to the last .Ar variable . If there are more variables than pieces, the remaining variables are assigned the null string. The .Ic read built-in will indicate success unless EOF, or a read error, is encountered on input, in which case failure is returned. .Pp By default, unless the .Fl r option is specified, the backslash .Pq Ql \e acts as an escape character, causing the following character, when that character is the escape character, or end delimiter character, to be treated literally when reading the record. This is the only form of quoting that applies. If an unescaped backslash is followed by a newline, the backslash and the newline will be deleted, and replaced by the contents from the following line, which is processed as if it had been part of the original line. This includes reading yet more input if necessary, until a line is read that contains or ends with an unescaped copy of the delimiter character. If the end delimiter (when it is not a newline) is escaped, it is treated as a normal character, and .Ic read continues looking for an unescaped end delimiter character. No other escape sequences are meaningful, the escape character is simply ignored. This happens as the record is read, before field splitting occurs. When .Fl r is used, no escaping occurs, no line joining happens, any input backslash is simply an input character. .Pp Note that if .Ar delim is given as an empty string, the nul character .Pq Ql \e0 is used as the delimiter. Other than this use, any nul characters in the input stream are silently deleted. .\" .Pp .It Ic readonly Ar name Ns Oo =value Oc ... .It Ic readonly Oo Fl p Oo Ar name ... Oc Oc .It Ic readonly Fl q Ar name ... With no options, the specified names are marked as read only, so that they cannot be subsequently modified or unset. The shell allows the value of a variable to be set at the same time it is marked read only by writing .Pp .Dl readonly name=value .Pp where the value often needs to be quoted, as explained for the .Ic export command. .Pp With no arguments the .Ic readonly command lists the names of all set read only variables. With the .Fl p option specified, the output will be formatted suitably for non-interactive use, and unset variables are included. When the .Fl p option is given, a list of variable names (without values) may also be specified, in which case output is limited to the named variables. .Pp With the .Fl q option, the .Ic readonly command tests the read-only status of the variables listed and exits with status 0 if all named variables are read-only, or with status 1 if any are not read-only. .Pp Other than as specified for .Fl q the .Ic readonly command normally exits with status 0. In all cases, if an unknown option, or an invalid option combination, or an invalid variable name, is given; or a variable which was already read-only is attempted to be set; the exit status will not be zero, a diagnostic message will be written to the standard error output, and a non-interactive shell will terminate. .\" .Pp .It Ic return Op Ar n Stop executing the current function or a dot command with return value of .Ar n or the value of the last executed command, if not specified. For portability, .Ar n should be in the range from 0 to 255. .Pp The POSIX standard says that the results of .Ic return outside a function or a dot command are unspecified. This implementation treats such a return as a no-op with a return value of 0 (success, true). Use the .Ic exit command instead, if you want to return from a script or exit your shell. .\" .Pp .It Ic set .It Ic set No { Fl o | Cm +o No } .It Ic set No { Fl options | Cm +options | Fl o Ar opt | Cm +o Ar opt } ... Oo Cm \-\|\- Oc Oo Ar arg ... Oc .It Ic set \-\|\- Oo Ar arg ... Oc .Pp The .Ic set command performs four different functions. .Pp With no arguments, .Ic set lists the names and values of all set shell variables. .Pp With a single option of either .Dq Fl o or .Dq Cm +o .Ic set outputs the current values of the options. In the .Fl o form, all options are listed, with their current values. In the .Cm +o form, the shell outputs a string that can later be used as a command to reset all options to their current values. .Pp If options are given, .Nm sets the specified option flags, or clears them as described in the .Sx Argument List Processing section. Note that not all options available on the command line are available to the .Ic set built-in command. However, in addition to the options listed there, when the .Dq "option name" .Pq Ar opt given to .Ic set Fl o is .Cm default all of the options are reset to the values they had immediately after .Nm initialization, before any startup scripts, or other input, had been processed. While this may be of use to users or scripts, its primary purpose is for use in the output of .Dq Ic set Cm +o , to avoid that command needing to list every available option. There is no .Cm +o default . .Pp The fourth use of the .Ic set command is to set the values of the shell's positional parameters to the specified arguments. To change the positional parameters with no possibility of changing any options, use .Dq \-\|\- as the first argument to .Ic set . If no following .Ar arg Ns s are present, the .Ic set command will clear all the positional parameters (equivalent to executing .Dq Li shift $# . ) Otherwise the following .Ar arg Ns s become .Li \&$1 , .Li \&$2 , \&..., and .Li \&$# is set to the number of .Ar arg Ns s present. The third and fourth forms may be combined, to set options, and the positional parameters, in one operation. Note that if it is possible that no .Ar arg Ns uments might be present, or if the first .Ar arg might begin with a minus .Pq Sq \&\- then the .Dq \-\|\- is required to distinguish this case from the first and third variants of this command, and an .Ar arg beginning with .Sq \&\- from being an attempt to set options. .\" .Pp .It Ic setvar Ar variable Ar value Assigns .Ar value to .Ar variable . (In general it is better to write .Li variable=value rather than using .Ic setvar . .Ic setvar is intended to be used in functions that assign values to variables whose names are passed as parameters.) .\" .Pp .It Ic shift Op Ar n Shift the positional parameters .Ar n times. If .Ar n is omitted, 1 is assumed. Each .Ic shift sets the value of .Li $1 to the previous value of .Li $2 , the value of .Li $2 to the previous value of .Li $3 , and so on, decreasing the value of .Li $# by one. The shift count must be less than or equal to the number of positional parameters ( .Dq Li $# ) before the shift. .\" .Pp .It Ic specialvar Ar variable ... For each .Ar variable name given, if the variable named is one which, in this .Nm , could be treated as a special variable, then cause that .Ar variable to be made special, undoing any effects of an earlier .Ic unset or assignment to the variable. If all .Ar variable Ns s given are recognized special variables in this .Nm the .Ic specialvar command will exit with status 0, otherwise 1. Invalid usage will result in an exit status of 2. .Pp Note that all variables capable of being special are created that way, this command is not required to cause that to happen. However should such a variable be imported from the environment, that will cause (for those special variables so designated) the special effects for that variable to be lost. Consequently, as the contents of the environment cannot be controlled, any script which desires to make use of the properties of most of the special variables should use this command, naming the variables required, to ensure that their special properties are available. .\" .Pp .It Ic times Prints two lines to standard output. Each line contains two accumulated time values, expressed in minutes and seconds (including fractions of a second.) The first value gives the user time consumed, the second the system time. .Pp The first output line gives the CPU and system times consumed by the shell itself. The second line gives the accumulated times for children of this shell (and their descendants) which have exited, and then been successfully waited for by the relevant parent. See .Xr times 3 for more information. .Pp .Ic times has no parameters, and exits with an exit status of 0 unless an attempt is made to give it an option. .\" .Pp .It Ic trap Ar action signal ... .It Ic trap \- .It Ic trap Op Fl l .It Ic trap Fl p Oo Ar signal ... Oc .It Ic trap Fl P Ar signal ... .It Ic trap Ar N signal ... .Pp Cause the shell to parse and execute action when any of the specified signals are received. The signals are specified by signal number or as the name of the signal. If .Ar signal is .Li 0 \" $0 or its equivalent, .Li EXIT , the action is executed when the shell exits. The .Ar action may be a null (empty) string, which causes the specified signals to be ignored. With .Ar action set to .Sq Li - the specified signals are set to their default actions. If the first .Ar signal is specified in its numeric form, then .Ar action can be omitted to achieve the same effect. This archaic, but still standard, form should not be relied upon, use the explicit .Sq Li - action. If no signals are specified with an action of .Sq Li - , all signals are reset. .Pp When the shell forks off a sub-shell, it resets trapped (but not ignored) signals to the default action. On non-interactive shells, the .Ic trap command has no effect on signals that were ignored on entry to the shell. On interactive shells, the .Ic trap command will catch or reset signals ignored on entry. .Pp Issuing .Ic trap with option .Fl l will print a list of valid signal names. .Ic trap without any arguments causes it to write a list of signals and their associated non-default actions to the standard output in a format that is suitable as an input to the shell that achieves the same trapping results. With the .Fl p flag, trap prints the same information for the signals specified, or if none are given, for all signals, including those where the action is the default. The .Fl P flag is similar, but prints only the action(s) associated with the named signals, at least (and usually only) one of which must be given. Nothing is printed if the action is the default, an empty line is printed for ignored signals. These variants of the trap command may be executed in a sub-shell .Pq "such as in a command substitution" , provided they appear as the initial sequence of commands in that sub-shell, in which case the state of traps from the parent of that sub-shell is reported. .Pp Examples: .Pp .Dl trap .Pp List trapped signals and their corresponding actions. .Pp .Dl trap -l .Pp Print a list of valid signals. .Pp .Dl trap '' INT QUIT tstp 30 .Pp Ignore signals INT QUIT TSTP USR1. .Pp .Dl trap date INT .Pp Run the .Dq date command (print the date) upon receiving signal INT. .Pp .Dl trap HUP INT .Pp Run the .Dq HUP command, or function, upon receiving signal INT. .Pp .Dl Ic eval Qo \&$( trap -P QUIT \&) Qc .Pp Parse and execute the action that would be invoked were a .Dv SIGQUIT received. .Pp .Dl trap 1 2 .Pp Reset the actions for signals 1 (HUP) and 2 (INT) to their defaults. .Bd -literal -offset indent traps=$(trap -p) # more commands ... trap 'action' SIG # more commands ... eval "$traps" .Ed .Pp Save the trap status, execute commands, changing some traps, and then reset all traps to their values at the start of the sequence. The .Fl p option is required in the first command here, or any signals that were previously untrapped (in their default states) and which were altered during the intermediate code, would not be reset by the final .Ic eval . .\" .Pp .It Ic type Op Ar name ... Interpret each .Ar name as a command and print the resolution of the command search. Possible resolutions are: shell keyword, alias, shell built-in, command, tracked alias and not found. For aliases the alias expansion is printed; for commands and tracked aliases the complete pathname of the command is printed. .\" .Pp .It Ic ulimit Oo Fl H Ns \*(Ba Ns Fl S Oc Op Fl a \*(Ba Fl btfdscmlrpnv Op Ar value Inquire about or set the hard or soft limits on processes or set new limits. The choice between hard limit (which no process is allowed to violate, and which may not be raised once it has been lowered) and soft limit (which causes processes to be signaled but not necessarily killed, and which may be raised) is made with these flags: .Bl -tag -width Fl .It Fl H set or inquire about hard limits .It Fl S set or inquire about soft limits. .El .Pp If neither .Fl H nor .Fl S is specified, the soft limit is displayed or both limits are set. If both are specified, then with .Fl a both are displayed, the soft followed by the hard limit, otherwise for setting, both limits are set, and for interrogating the soft limit is displayed. .Pp The limit to be interrogated or set, then, is chosen by specifying any one of these flags: .Bl -tag -width Fl .It Fl a show all the current limits (it is an error to attempt to set the limits by giving a .Ar value ) .It Fl b the socket buffer size of a process (bytes) .It Fl c the largest core dump size that can be produced (512-byte blocks) .It Fl d the data segment size of a process (kilobytes) .It Fl f the largest file that can be created (512-byte blocks) .It Fl l how much memory a process can lock with .Xr mlock 2 (kilobytes) .It Fl m the total physical memory that can be in use by a process (kilobytes) .It Fl n the number of files a process can have open at once .It Fl p the number of processes this user can have at one time .It Fl r the number of threads this user can have at one time .It Fl s the stack size of a process (kilobytes) .It Fl t CPU time (seconds) .It Fl v how large a process address space can be .El .Pp If none of these is specified, it is the limit on file size that is shown or set. If value is specified, the limit is set to that number; otherwise the current limit is displayed. .Pp Limits of an arbitrary process can be displayed or set using the .Xr sysctl 8 utility. .\" .Pp .It Ic umask Oo Fl S Oc Op Ar mask Set the value of umask (see .Xr umask 2 ) to the specified octal value. If the argument is omitted, the umask value is printed. With .Fl S a symbolic form is used instead of an octal number. .\" .Pp .It Ic unalias Oo Fl a Oc Op Ar name If .Ar name is specified, the shell removes that alias. If .Fl a is specified, all aliases are removed. .\" .Pp .It Ic unset Oo Fl efvx Oc Ar name ... If .Fl v is specified, the specified variables are unset and unexported. Readonly variables cannot be unset. If .Fl f is specified, the specified functions are undefined. If .Fl e is given, the specified variables are unexported, but otherwise unchanged, alternatively, if .Fl x is given, the exported status of the variable will be retained, even after it is unset. .Pp If no flags are provided .Fl v is assumed. If .Fl f is given with one of the other flags, then the named variables will be unset, or unexported, and functions of the same names will be undefined. The .Fl e and .Fl x flags both imply .Fl v . If .Fl e is given, the .Fl x flag is ignored. .Pp The exit status is 0, unless an attempt was made to unset a readonly variable, in which case the exit status is 1. It is not an error to unset (or undefine) a variable (or function) that is not currently set (or defined.) .\" .Pp .It Ic wait Oo Fl n Oc Oo Fl p Ar var Oc Op Ar job ... Wait for the specified jobs to complete and return the exit status of the last job in the parameter list, or 127 if that job is not a current child of the shell. .Pp If no .Ar job arguments are given, wait for all jobs to complete and then return an exit status of zero (including when there were no jobs, and so nothing exited.) .Pp With the .Fl n option, wait instead for any one of the given .Ar job Ns s, or if none are given, any job, to complete, and return the exit status of that job. If none of the given .Ar job arguments is a current child of the shell, or if no .Ar job arguments are given and the shell has no unwaited for children, then the exit status will be 127. .Pp The .Fl p Ar var option allows the process (or job) identifier of the job for which the exit status is returned to be obtained. The variable named (which must not be readonly) will be unset initially, then if a job has exited and its status is being returned, set to the identifier from the arg list (if given) of that job, or the lead process identifier of the job to exit when used with .Fl n and no job arguments. Note that .Fl p with neither .Fl n nor .Ar job arguments is useless, as in that case no job status is returned, the variable named is simply unset. .Pp If the wait is interrupted by a signal, its exit status will be greater than 128, and .Ar var , if given, will remain unset. .Pp Once waited upon, by specific process number or job-id, or by a .Ic wait with no arguments, knowledge of the child is removed from the system, and it cannot be waited upon again. .Pp Note than when a list of jobs are given, more that one argument might refer to the same job. In that case, if the final argument represents a job that is also given earlier in the list, it is not defined whether the status returned will be the exit status of the job, or 127 indicating that the child no longer existed when the wait command reached the later argument in the list. In this .Nm the exit status will be that from the job. .Nm waits for each job exactly once, regardless of how many times (or how many different ways) it is listed in the arguments to .Ic wait . That is .Bd -literal -offset indent -compact wait 100 100 100 .Ed is identical to .Bd -literal -offset indent -compact wait 100 .Ed .El .\" .\" .Ss Job Control .\" Each process (or set of processes) started by .Nm is created as a .Dq job and added to the jobs table. When enabled by the .Fl m option .Pq aka Fl o Cm monitor when the job is created, .Nm places each job (if run from the top level shell) into a process group of its own, which allows control of the process(es), and its/their descendants, as a unit. When the .Fl m option is off, or when started from a sub-shell environment, jobs share the same process group as the parent shell. The .Fl m option is enabled by default in interactive shells with a terminal as standard input and standard error. .Pp Jobs with separate process groups may be stopped, and then later resumed in the foreground (with access to the terminal) or in the background (where attempting to read from the terminal will result in the job stopping.) A list of current jobs can be obtained using the .Ic jobs built-in command. Jobs are identified using either the process identifier of the lead process of the job (the value available in the special parameter .Dq Dv \&! if the job is started in the background), or using percent notation. Each job is given a .Dq job number which is a small integer, starting from 1, and can be referenced as .Dq Li \&% Ns Ar n where .Ar n is that number. Note that this applies to jobs both with and without their own process groups. Job numbers are shown in the output from the .Ic jobs command enclosed in brackets .Po .Sq Li \&[ and .Sq Li \&] .Pc . Whenever the job table becomes empty, the numbers begin at one again. In addition, there is the concept of a current, and a previous job, identified by .Dq Li \&%+ .Po or .Dq Li \&%% or even just .Dq Li \&% .Pc , and a previous job, identified by .Dq Li \&%\- . Whenever a background job is started, or a job is resumed in the background, it becomes the current job. The job that was the current job (prepare for a big surprise here, drum roll..., wait for it...\&) becomes the previous job. When the current job terminates, the previous job is promoted to be the current job. In addition the form .Dq Li \&% Ns Ar string\^ finds the job for which the command starts with .Ar string and the form .Dq Li \&%? Ns Ar string\^ finds the job which contains the .Ar string in its command somewhere. Both forms require the result to be unambiguous. For this purpose the .Dq command is that shown in the output from the .Ic jobs command, not the original command line. .Pp The .Ic bg , .Ic fg , .Ic jobid , .Ic jobs , .Ic kill , and .Ic wait commands all accept job identifiers as arguments, in addition to process identifiers (larger integers). See the .Sx Built-ins section above, and .Xr kill 1 , for more details of those commands. In addition, a job identifier (using one of the .Dq \&% forms ) issued as a command, without arguments, is interpreted as if it had been given as the argument to the .Ic fg command. .Pp To cause a foreground process to stop, enter the terminal's .Ic stop character (usually control-Z). To cause a background process to stop, send it a .Dv STOP signal, using the kill command. A useful function to define is .Bd -literal -offset indent stop() { kill -s STOP "${@@:-%%}"; } .Ed .Pp The .Ic fg command resumes a stopped job, placing it in the foreground, and .Ic bg resumes a stopped job in the background. The .Ic jobid command provides information about process identifiers, job identifiers, and the process group identifier, for a job. .Pp Whenever a sub-shell is created, the jobs table becomes invalid (the sub-shell has no children.) However, to enable uses like .Bd -literal -offset indent PID=$(jobid -p %1) .Ed .Pp the table is only actually cleared in a sub-shell when needed to create the first job there (built-in commands run in the foreground do not create jobs.) Note that in this environment, there is no useful current job .Dq ( Li \&%% actually refers to the sub-shell itself, but is not accessible) but the job which is the current job in the parent can be accessed as .Dq Li \&%\- . .\" .\" .Ss Command Line Editing .\" When .Nm is being used interactively from a terminal, the current command and the command history (see .Ic fc in the .Sx Built-ins section) can be edited using emacs-mode or vi-mode command-line editing. The command .Ql set -o emacs (or .Fl E option) enables emacs-mode editing. The command .Ql set -o vi (or .Fl V option) enables vi-mode editing and places the current shell process into vi insert mode. (See the .Sx Argument List Processing section above.) .Pp The vi-mode uses commands similar to a subset of those described in the .Xr vi 1 man page. With vi-mode enabled, .Nm sh can be switched between insert mode and command mode. It's similar to .Ic vi : pressing the .Aq ESC key will throw you into vi command mode. Pressing the .Aq return key while in command mode will pass the line to the shell. .Pp The emacs-mode uses commands similar to a subset available in the .Ic emacs editor. With emacs-mode enabled, special keys can be used to modify the text in the buffer using the control key. .Pp .Nm uses the .Xr editline 3 library. See .Xr editline 7 for a list of the possible command bindings, and the default settings in emacs and vi modes. Also see .Xr editrc 5 for the commands that can be given to configure .Xr editline 7 in the file named by the .Ev EDITRC parameter, or a file used with the .Ic inputrc built-in command, or using .Xr editline 7 Ap s configuration command line. .Pp When command line editing is enabled, the .Xr editline 7 functions control printing of the .Ev PS1 and .Ev PS2 prompts when required. As, in this mode, the command line editor needs to keep track of what characters are in what position on the command line, care needs to be taken when setting the prompts. Normal printing characters are handled automatically, however mode setting sequences, which do not actually display on the terminal, need to be identified to .Xr editline 7 . This is done, when needed, by choosing a character that is not needed anywhere in the prompt, including in the mode setting sequences, any single character is acceptable, and assigning it to the shell parameter .Dv PSlit . Then that character should be used, in pairs, in the prompt string. Between each pair of .Dv PSlit characters are mode setting sequences, which affect the printing attributes of the following (normal) characters of the prompt, but do not themselves appear visibly, nor change the terminal's cursor position. .Pp Each such sequence, that is .Dv PSlit character, mode setting character sequence, and another .Dv PSlit character, must currently be followed by at least one following normal prompt character, or it will be ignored. That is, a .Dv PSlit character cannot be the final character of .Ev PS1 or .Ev PS2 , nor may two .Dv PSlit delimited sequences appear adjacent to each other. Each sequence can contain as many mode altering sequences as are required however. Only the first character from .Dv PSlit will be used. When set .Dv PSlit should usually be set to a string containing just one character, then it can simply be embedded in .Ev PS1 (or .Ev PS2 ) as in .Pp .D1 Li PS1=\*q${PSlit} Ns Ar mset\^ Ns Li ${PSlit}XYZ${PSlit} Ns Ar mclr\^ Ns Li ${PSlit}ABC\*q .Pp The prompt visible will be .Dq XYZABC with the .Dq XYZ part shown according as defined by the mode setting characters .Ar mset , and then cleared again by .Ar mclr . See .Xr tput 1 for one method to generate appropriate mode sequences. Note that both parts, XYZ and ABC, must each contain at least one character. .Pp If .Dv PSlit is unset, which is its initial state, or set to a null string, no literal character will be defined, and all characters of the prompt strings will be assumed to be visible characters (which includes spaces etc.) To allow smooth use of prompts, without needing redefinition, when .Xr editline 7 is disabled, the character chosen should be one which will be ignored by the terminal if received, as when .Xr editline 7 is not in use, the prompt strings are simply written to the terminal. For example, setting: .\" XXX: PS1 line is too long for -offset indent .Bd -literal -offset left PSlit="$(printf\ '\e1')" PS1="${PSlit}$(tput\ bold\ blink)${PSlit}\e$${PSlit}$(tput\ sgr0)${PSlit}\ " .Ed .Pp will arrange for the primary prompt to be a bold blinking dollar sign, if supported by the current terminal, followed by an (ordinary) space, and, as the SOH (control-A) character .Pq Sq \e1 will not normally affect a terminal, this same prompt will usually work with .Xr editline 7 enabled or disabled. .Sh ENVIRONMENT .Bl -tag -width MAILCHECK .It Ev CDPATH The search path used with the .Ic cd built-in. .It Ev EDITRC Gives the name of the file containing commands for .Xr editline 7 . See .Xr editrc 5 for possible content and format. The file is processed, when in interactive mode with command line editing enabled, whenever .Ev EDITRC is set (even with no actual value change,) and if command line editing changes from disabled to enabled, or the editor style used is changed. (See the .Fl E and .Fl V options of the .Ic set built-in command, described in .Sx Built-ins above, which are documented further above in .Sx Argument List Processing . ) If unset .Dq $HOME/.editrc is used. .It Ev ENV Names the file sourced at startup by the shell. Unused by this shell after initialization, but is usually passed through the environment to descendant shells. See the .Sx Invocation section above for details of how .Ev ENV is processed and used. .It Ev EUSER Set to the login name of the effective user id running the shell, as returned by .Bd -literal -offset indent -compact getpwuid(geteuid())->pw_name .Ed .Po See .Xr getpwuid 3 and .Xr geteuid 2 for more details. .Pc This is obtained each time .Ev EUSER is expanded, so changes to the shell's execution identity cause updates without further action. If unset, it returns nothing. If set it loses its special properties, and is simply a variable. See the .Ic specialvar built-in command for remedial action. .It Ev HISTSIZE The number of lines in the history buffer for the shell. .It Ev HOME Set automatically by .Xr login 1 from the user's login directory in the password file .Pq Xr passwd 5 . This environment variable also functions as the default argument for the .Ic cd built-in. .It Ev HOSTNAME Set to the current hostname of the system, as returned by .Xr gethostname 3 . This is obtained each time .Ev HOSTNAME is expanded, so changes to the system's name are reflected without further action. If unset, it returns nothing. If set it loses its special properties, and is simply a variable. See the .Ic specialvar built-in command for remedial action. .It Ev IFS Input Field Separators. This is normally set to .Aq space , .Aq tab , and .Aq newline . .Sx White Space Splitting section for more details. .It Ev LANG The string used to specify localization information that allows users to work with different culture-specific and language conventions. See .Xr nls 7 . .It Dv LINENO The current line number in the script or function. See the section .Sx LINENO below for more details. .It Ev MAIL The name of a mail file, that will be checked for the arrival of new mail. Overridden by .Ev MAILPATH . The check occurs just before .Ev PS1 is written, immediately after reporting jobs which have changed status, in interactive shells only. New mail is considered to have arrived if the monitored file has increased in size since the last check. .\" .It Ev MAILCHECK .\" The frequency in seconds that the shell checks for the arrival of mail .\" in the files specified by the .\" .Ev MAILPATH .\" or the .\" .Ev MAIL .\" file. .\" If set to 0, the check will occur at each prompt. .It Ev MAILPATH A colon .Dq \&: separated list of file names, for the shell to check for incoming mail. This environment setting overrides the .Ev MAIL setting. There is a maximum of 10 mailboxes that can be monitored at once. .It Ev NBSH_INVOCATION When .Nm starts, after it has processed its arguments, and imported variables from the environment, this variable is set to a string of one or more characters which indicate the way the command line was processed. This is intended to be used in the startup scripts .Pq see Sx Invocation to allow them to determine what actions are appropriate to take. .Ev NBSH_INVOCATION is marked .Dq not to be exported . Apart from the way it is initialized, and that it overrides any value that may have been set in the environment, there is nothing special about it. It can be unset, or altered, with no ramifications, other than whatever effect this might have on its use in the startup scripts. .Pp When the value of this variable remains as set at startup by .Nm the following characters may appear in the value, in the circumstances described. Any present will always appear in ASCII lexical order, as they appear below (to make testing the value easier to code). .Pp .Bl -tag -width M__ -offset indent -compact .It \&! Always present when set by .Nm , and is always first. No specific meaning is attributed to this character. .It \&\- Set when the first character of .Va argv[0] as set when the shell was invoked was a dash .Pq Sq \&\- . .It \&0 Set when at startup, the special parameter .Dv \&$# has the value 0. That is, no arguments were given to the script in the case that there is a script. .It \&c The .Fl c option was given on the command line. .It \&f Neither the .Fl c nor .Fl s options were present on the command line, but there is at least one non-option argument, which will then be interpreted as the name of the .Ar command_file to process. .It \&i The shell is interactive. At startup this indicates that .Sq i will appear in the value of the special parameter .Va \&$\- . However, the special parameter will alter as the .Fl i option is manipulated by the .Ic set built-in command, but .Ev NBSH_INVOCATION is never subsequently altered by the shell itself (unless manipulated by a regular variable operations). .It \&l The shell is a login shell. As with .Sq i (the same operational conditions apply) this character will be present if the .Sq l is present in .Va \&$- when the shell is starting. Note that if .Sq l is present, and .Sq \&\- is not, then the shell was invoked with the .Fl l option on the command line (or the equivalent .Fl o Em login ) . On the other hand, if .Sq \&\- appears, and .Sq l does not, then the shell was invoked with the .Cm +l option (or its equivalent) on the command line. If both .Sq \&\- and .Sq l appear, then the shell is a normal login shell, the .Fl l option might have been given, but had no effect. If neither .Sq \&\- nor .Sq l appear, then the shell is not a login shell, and was never intended to be. The .Cm +l option might have been given, but had no effect. .It \&p The shell was started as a privileged (set user id) process. This indicates that the .Fl p option must have been given on the command line, or privileges would have been dropped. .It \&s The shell will read commands from standard input. The .Fl s option was given, or implied. This does not imply that the shell is interactive. .El .It Ev PATH The default search path for executables. See the .Sx Path Search section above. .It Ev POSIXLY_CORRECT If set in the environment upon initialization of the shell, then the shell option .Ic posix will be set. .Po See the description of the .Ic set command in the .Sx Built-ins section. .Pc After initialization it is unused by the shell, but is usually passed through the environment to descendant processes, including other instances of the shell, which may interpret it in a similar way. .It Ev PPID The process identified of the parent process of the current shell. This value is set at shell startup, ignoring any value in the environment, and then made readonly. .It Ev PS1 The primary prompt string, which defaults to .Dq Li "$ " , unless you are the superuser, in which case it defaults to .Dq Li "# " . This string is subject to parameter, arithmetic, and if enabled by setting the .Ic promptcmds option, command substitution before being output. During execution of commands used by command substitution, execution tracing, the .Ic xtrace .Ic ( set Fl x ) option is temporarily disabled. If .Ic promptcmds is not set and the prompt string uses command substitution, the prompt used will be an appropriate error string. For other expansion errors, the prompt will become an empty string, without an error message. To verify parsing of .Ev PS1 , the method suggested for .Ev ENV can be used. .It Ev PS2 The secondary prompt string, which defaults to .Dq Li "> " . After expansion (as for .Ev PS1 ) it is written whenever more input is required to complete the current command. .It Ev PS4 is output, after expansion as described for .Ev PS1 , as a prefix for each line when execution trace .Ic ( set Fl x ) is enabled. .Ev PS4 defaults to .Dq Li "+ " . .It Ev PSc Initialized by the shell, ignoring any value from the environment, to a single character string, either .Sq \&# or .Sq \&$ , depending upon whether the current user is the superuser or not. This is intended for use when building a custom .Ev PS1 . If a privileged shell has its privileges removed by clearing the .Fl p option, an attempt will be made to be reset .Ev PSc to .Dq \&# or .Dq \&$ , as appropriate for its new privilege level. .It Ev PSlit Defines the character which may be embedded in pairs, in .Ev PS1 or .Ev PS2 to indicate to .Xr editline 7 that the characters between each pair of occurrences of the .Dv PSlit character will not appear in the visible prompt, and will not cause the terminal's cursor to change position, but rather set terminal attributes for the following prompt character(s) at least one of which must be present. See .Sx Command Line Editing above for more information. .It Ev RANDOM Returns a different pseudo-random integer, in the range [0,32767] each time it is accessed. .Ev RANDOM can be assigned an integer value to seed the PRNG. If the value assigned is a constant, then the sequence of values produces on subsequent references of .Ev RANDOM will repeat after the next time the same constant is assigned. Note, this is not guaranteed to remain constant from one version of the shell to another \(en the PRNG algorithm, or seeding method is subject to change. If .Ev RANDOM is assigned an empty value (null string) then the next time .Ev RANDOM is accessed, it will be seeded from a more genuinely random source. The sequence of pseudo-random numbers generated will not be able to be generated again (except by luck, whether good or bad, depends!) This is also how the initial seed is generated, if none has been assigned before .Ev RANDOM is first accessed after shell initialization. Should the error message .Dq "RANDOM initialisation failed" appear on standard error, it indicates that the source of good random numbers was not available, and .Ev RANDOM has instead been seeded with a more predictable value. The following sequence of random numbers will not be as unpredictable as they otherwise would be. .It Ev SECONDS Returns the number of seconds since the current shell was started. If unset, it remains unset, and returns nothing, unless set again. If set, it loses its special properties, and becomes a normal variable. See the .Ic specialvar built-in command for remedial action. .It Ev START_TIME Initialized by the shell to the number of seconds since the Epoch (see .Xr localtime 3 ) when the shell was started. The value of .Dl $(( Ns Ev START_TIME + Ev SECONDS Ns )) represents the current time, if .Ev START_TIME has not been modified, and .Ev SECONDS has not been set or unset. .It Ev TERM The default terminal setting for the shell. This is inherited by children of the shell, and is used in the history editing modes. .It Ev ToD When referenced, uses the value of .Ev ToD_FORMAT (or .Dq \&%T if .Ev ToD_FORMAT is unset) as the format argument to .Xr strftime 3 to encode the current time of day, in the time zone defined by .Ev TZ if set, or current local time if not, and returns the result. If unset .Ev ToD returns nothing. If set, it loses its special properties, and becomes a normal variable. See the .Ic specialvar built-in command for remedial action. .It Ev ToD_FORMAT Can be set to the .Xr strftime 3 format string to be used when expanding .Ev ToD . Initially unset. .It Ev TZ If set, gives the time zone (see .Xr localtime 3 , .Xr environ 7 ) to use when formatting .Ev ToD and if exported, other utilities that deal with times. If unset, the system's local wall clock time zone is used. .\" .\" ========================================================== .\" This is explicitly last, not in sort order - please leave! .It Ev NETBSD_SHELL Unlike the variables previously mentioned, this variable is somewhat strange, in that it cannot be set, inherited from the environment, modified, or exported from the shell. If set, by the shell, it indicates that the shell is the .Ic sh defined by this manual page, and gives its version information. It can also give information in additional space separated words, after the version string. If the shell was built as part of a reproducible build, the relevant date that was used for that build will be included. Finally, any non-standard compilation options, which may affect features available, that were used when building the shell will be listed. .Ev NETBSD_SHELL behaves like any other variable that has the read-only and un-exportable attributes set. .El .Ss Dv LINENO .Dv LINENO is in many respects a normal shell variable, containing an integer value, and can be expanded using any of the forms mentioned above which can be used for any other variable. .Pp .Dv LINENO can be exported, made readonly, or unset, as with any other variable, with similar effects. Note that while being readonly prevents later attempts to set, or unset, .Dv LINENO , it does not prevent its value changing. References to .Dv LINENO .Pq "when not unset" always obtain the current line number. However, .Dv LINENO should normally not ever be set or unset. In this shell setting .Dv LINENO reverses the effect of an earlier .Ic unset , but does not otherwise affect the value obtained. If unset, .Dv LINENO should not normally be set again, doing so is not portable. If .Dv LINENO is set or unset, different shells act differently. The value of .Dv LINENO is never imported from the environment when the shell is started, though if present there, as with any other variable, .Dv LINENO will be exported by this shell. .Pp .Dv LINENO is set automatically by the shell to be the number of the source line on which it occurs. When exported, .Dv LINENO is exported with its value set to the line number it would have had had it been referenced on the command line of the command to which it is exported. Line numbers are counted from 1, which is the first line the shell reads from any particular file. For this shell, standard input, including in an interactive shell, the user's terminal, is just another file and lines are counted there as well. However note that not all shells count interactive lines this way, it is not wise to rely upon .Dv LINENO having a useful value, except in a script, or a function. .Pp The role of .Dv LINENO in functions is less clear. In some shells, .Dv LINENO continues to refer to the line number in the script which defines the function, in others lines count from one within the function, always (and resume counting normally once the function definition is complete) and others count in functions from one if the function is defined interactively, but otherwise just reference the line number in the script in which the function is defined. This shell gives the user the option to choose. If the .Fl L flag (the .Ic local_lineno option, see .Sx Argument List Processing ) is set, when the function is defined, then the function defaults to counting lines with one being the first line of the function. When the .Fl L flag is not set, the shell counts lines in a function definition in the same continuous sequence as the lines that surround the function definition. Further, if .Dv LINENO is made local (see .Sx Built-ins above) inside the function, the function can decide which behavior it prefers. If .Dv LINENO is made local and inherited, and not given a value, as in .Dl local Fl I Dv LINENO then from that point in the function, .Dv LINENO will give the line number as if lines are counted in sequence with the lines that surround the function definition (and any other function definitions in which this is nested.) If .Dv LINENO is made local, and in that same command, given a value, as .Dl local Oo Fl I Ns | Ns Fl N Oc Dv LINENO Ns = Ns Ar value then .Dv LINENO will give the line number as if lines are counted from one from the beginning of the function. The value nominally assigned in this case is irrelevant, and ignored. For completeness, if lineno is made local and unset, as in .Dl local Fl N Dv LINENO then .Dv LINENO is simply unset inside the function, and gives no value at all. .Pp Now for some technical details. The line on which .Dv LINENO occurs in a parameter expansion, is the line that contains the .Sq \&$ that begins the expansion of .Dv LINENO . In the case of nested expansions, that .Sq \&$ is the one that actually has .Dv LINENO as its parameter. In an arithmetic expansion, where no .Sq \&$ is used to evaluate .Dv LINENO but .Dv LINENO is simply referenced as a variable, then the value is the line number of the line that contains the .Sq L of .Dv LINENO . For functions line one of the function definition (when relevant) is the line that contains the first character of the function name in the definition. When exported, the line number of the command is the line number where the first character of the word which becomes the command name occurs. .Pp When the shell opens a new file, for any reason, it counts lines from one in that file, and then resumes its original counting once it resumes reading the previous input stream. When handling a string passed to .Ic eval the line number starts at the line on which the string starts, and then if the string contains internal newline characters, those characters increase the line number. This means that references to .Dv LINENO in such a case can produce values larger than would be produced by a reference on the line after the .Ic eval . .Sh FILES .Bl -item .It .Pa $HOME/.profile .It .Pa /etc/profile .El .Sh EXIT STATUS Errors that are detected by the shell, such as a syntax error, will cause the shell to exit with a non-zero exit status. If the shell is not an interactive shell, the execution of the shell file will be aborted. Otherwise the shell will return the exit status of the last command executed, or if the exit built-in is used with a numeric argument, it will return the argument. .Sh SEE ALSO .Xr csh 1 , .Xr echo 1 , .Xr getopt 1 , .Xr ksh 1 , .Xr login 1 , .Xr printf 1 , .Xr test 1 , .Xr editline 3 , .Xr getopt 3 , .\" .Xr profile 4 , .Xr editrc 5 , .Xr passwd 5 , .Xr editline 7 , .Xr environ 7 , .Xr nls 7 , .Xr sysctl 8 .Sh HISTORY A .Nm command appeared in .At v1 . It was replaced in .At v7 with a version that introduced the basis of the current syntax. That was, however, unmaintainable so we wrote this one. This .Nx .Nm is a much modified descendant of the ash shell written by Ken Almquist. .Sh BUGS Setuid shell scripts should be avoided at all costs, as they are a significant security risk. .Pp The characters generated by filename completion should probably be quoted to ensure that the filename is still valid after the input line has been processed. .Pp Job control of compound statements (loops, etc) is a complete mess. .Pp The .Fl Z option to the .Ic jobs built-in command is bizarre, but is implemented this way to be compatible with the similar option in .Xr zsh 1 . .Pp Many, many, more. (But less than there were...) @ 1.258 log @sh(1): touch up markup for the ENV example Don't use Dq in a literal display, ascii quotes are \*q While here mark up as literal a few things around this example. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.257 2023/09/01 01:57:54 kre Exp $ d2302 1 a2302 1 .Ss White Space Splitting (Field Splitting) a2306 3 and .Dq Li $@@ even if it did, @ 1.257 log @ At the request of bad@@ enhance the synopsis of the set built-in command to include explicit mention of the -o opt and +o opt forms. Fix the synopsis to have the 4 forms that the description of the utility discusses, rather than expecting users to understand that the 3rd and 4th forms of the command were combined into the 3rd synopsis format. After doing that, the options in the 3rd format no longer need to be optional, so now all 4 formats are distinct (previously, the third, omitting everything that was optional, and the first, could not be distinguished). While here, some wording and formatting "improvements" as well (nothing too serious). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.256 2023/08/04 15:31:40 jschauma Exp $ d139 1 a139 1 .Dq \&. d146 1 a146 1 .Pq \&$HOME , d167 1 a167 1 .Dl eval printf '%s\e\en' Dq \&${ENV} d191 1 a191 1 .Dq .shinit @ 1.256 log @tyops: * redicection -> redirection * escaoed -> escaped Noted by J. Lewis Muir on netbsd-docs@@ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.255 2022/12/20 17:51:54 kre Exp $ d3728 4 a3731 3 .It set .It set { Fl o | Cm +o } .It Ic set Oo { Fl options | Cm +options } ... Oc Oo Cm \-\|\- Oc Oo Ar arg ... Oc d3755 4 a3758 2 If options are given, it sets the specified option flags, or clears them as described in the d3768 1 d3793 3 a3795 1 If no following arguments are present, the d3800 3 a3802 1 Otherwise the following arguments become d3808 3 a3810 1 is set to the number of arguments present. d3812 16 a3827 1 and the argument list, in one operation. @ 1.255 log @ More markup errors. \+ was intended to be \&+ and .EV .Ev of course. As best I can tell, the rest of what mandoc -Wall complains about is incorrect (it could probably be avoided by adding more markup, but there doesn't seem to be any point). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.254 2022/12/20 16:48:57 kre Exp $ d1003 1 a1003 1 depending upon the redicection operator used. d3635 1 a3635 1 If the end delimiter (when it is not a newline) is escaoed, @ 1.254 log @ Using .Cm Cm makes no sense at all - no idea what I was thinking there (perhaps just an editing error). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.253 2022/12/20 01:18:42 uwe Exp $ d125 1 a125 1 .Cm \+l d1785 1 a1785 1 .EV IFS @ 1.253 log @sh(1): Fix markup. -compact must be last. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.252 2022/12/11 08:23:10 kre Exp $ d427 1 a427 1 .Cm Cm \&+o Em login Pc , @ 1.252 log @ It appears that POSIX intends to add a -d X option to the read command in its next version, so it can be used as -d '' (to specify a \0 end character for the record read, rather than the default \n) to accompany find -print0 and xargs -0 options (also likely to be added). Add support for -d now. While here fix a bug where escaped nul chars (\ \0) in non-raw mode were not being dropped, as they are when not escaped (if not dropped, they're still not used in any useful way, they just ended the value at that point). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.251 2022/10/30 01:19:08 kre Exp $ d2770 1 a2770 1 .Bd -unfilled -compact -offset indent d4755 1 a4755 1 .Bl -compact -tag -width M__ -offset indent @ 1.252.2.1 log @Pull up following revision(s) (requested by uwe in ticket #11): bin/sh/sh.1: revision 1.253 sh(1): Fix markup. -compact must be last. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.252 2022/12/11 08:23:10 kre Exp $ d2770 1 a2770 1 .Bd -unfilled -offset indent -compact d4755 1 a4755 1 .Bl -tag -width M__ -offset indent -compact @ 1.251 log @ Note in the description of "jobs -p" that the process id returned is also the process group identifier (that's a requirement from POSIX, and is what we have always done - just not been explicit about in sh.1). Add a note that this value and $! are not necessarily the same (currently, and perhaps forever, never the same in a pipeline with 2 or more elements). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.250 2022/09/18 06:03:19 kre Exp $ d34 1 a34 2 .\" RIP Noi, October 6, 1959 -- .Dd August 26, 2022 d3585 1 a3585 1 .It Ic read Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Op Ar ... d3591 9 a3599 3 Then a line is read from the standard input. The trailing newline is deleted from the line and the line is split as described in the field splitting section of the d3622 5 a3626 3 .Dq \e acts as an escape character, causing the following character to be treated literally. d3630 1 a3630 1 and replaced by the contents of the following line, d3633 24 a3656 2 until a line is read that is not terminated by an unescaped backslash immediately before the newline. @ 1.250 log @Add the -l option (aka -o login): be a login shell. Meaningful only on the command line (with both - and + forms) - overrides the presence (or otherwise) of a '-' as argv[0][0]. Since this allows any shell to be a login shell (which simply means that it runs /etc/profile and ~/.profile at shell startup - there are no other side effects) add a new, always set at startup, variable NBSH_INVOCATION which has a char string as its value, where each char has a meaning, more or less related to how the shell was started. See sh(1). This is intended to allow those startup scripts to tailor their behaviour to the nature of this particular login shell (it is possible to detect whether a shell is a login shell merely because of -l, or whether it would have been anyway, before the -l option was added - and more). The var could also be used to set different values for $ENV for different uses of the shell. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.249 2022/09/16 19:25:09 kre Exp $ d3313 5 a3317 1 process. @ 1.249 log @ More wording improvements. There might be more to come. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.248 2022/09/16 17:32:18 kre Exp $ d34 2 a35 1 .Dd January 7, 2022 d38 1 a38 1 .ds flags abCEeFfhIiLmnpquVvXx d123 5 d129 4 a132 1 .Sq - , d135 2 a136 1 This is normally done automatically by the system d422 17 d4690 138 @ 1.248 log @ Minor wording improvements. Note these do not alter anything about what the man page specifies, just say a couple of things in a slightly better way, hence no Dd update accompanies this change (deliberately). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.247 2022/09/16 17:29:21 kre Exp $ d888 2 a889 1 If it does, it replaces it in the input stream with its value. d940 2 a941 1 variable assignments recognized in item 1 affect the current shell. d973 5 d1127 1 a1127 1 and exported for the benefit of programs executed with the function. d1310 4 a1313 3 child of the invoking shell (unless it is a shell built-in, in which case it executes in the current shell \(em but any effect it has on the environment is wiped). d1753 2 a1754 1 expansion occurs within a double-quoted string it expands to a single d1758 3 a1760 1 variable, or by a d1769 7 d1852 2 a1853 2 Field Splitting is performed on fields generated by step (1) except for Tilde Expansion. @ 1.247 log @ Move a comment that used to be in the correct place, once upon a time, back where it belongs, and make it stand out more, so other text is less likely to find itself pushed between the comment and the text to which it appears. This change should make no visible difference to the man page displayed. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.246 2022/09/16 17:25:09 kre Exp $ d162 1 a162 1 which is not performed here, d261 1 a261 2 Some options have only a long name, they are described after the flag options, they are used with d272 1 a272 1 Specifying a dash d413 2 a414 1 Turn on job control (set automatically at shell startup when interactive). d1783 1 a1783 1 .It Dv \- No (hyphen, or minus) @ 1.246 log @ Whitespace. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.245 2022/09/15 18:00:36 kre Exp $ a4800 1 .\" This is explicitly last, not in sort order - please leave! d4836 3 @ 1.245 log @ Correct spelling of terminal (it doesn't have a 2nd m). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.244 2022/08/19 13:37:03 kre Exp $ d3194 1 a3194 1 .It Ic jobid Oo Fl g Ns \&| Ns Fl j Ns \&| Ns Fl p Oc Op Ar job d3576 1 a3576 1 This includes reading yet more input if necessary, @ 1.244 log @ Improve the description of the read builtin command. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.243 2022/01/07 05:30:30 lukem Exp $ d395 1 a395 1 terminmal type devices. @ 1.243 log @sh(1): improve getopts docs for optstring leading : getopts has different behaviour if the leading character of optstring is `:', so describe in more detail: - no errors are printed (already there) - unknown options set var to `?' and OPTARG to the unknown option - missing arguments set var to `:' and OPTARG to the option name Slight rewording of other paragraphs for more clarity. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.242 2022/01/07 05:10:30 lukem Exp $ d3540 1 a3540 1 is printed if the d3547 6 a3552 2 section above, and the pieces are assigned to the variables in order. If there are more pieces than variables, the remaining pieces d3555 2 a3556 1 that separated them) are assigned to the last variable. d3561 2 a3562 1 built-in will indicate success unless EOF is encountered on input, in d3571 8 a3578 2 If a backslash is followed by a newline, the backslash and the newline will be deleted. @ 1.242 log @sh(1): fix formatting warnings @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.241 2021/11/21 16:23:20 kre Exp $ d2935 1 a2935 1 optionally followed by a colon to indicate that the option requires an d2972 2 a2973 2 If a letter is followed by a colon, the option is expected to have an argument which may or may not be separated from it by whitespace. d2978 1 a2978 1 to a d2983 21 a3003 4 and write output to standard error. By specifying a colon as the first character of .Ar optstring all errors will be ignored. @ 1.241 log @ Improve the however-many-negatives wording even more. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.240 2021/11/20 17:18:31 rillig Exp $ d34 1 a34 1 .Dd November 20, 2021 d2569 1 a2569 1 .Po \&\$ Ns Ev PWD Ns Pc d3159 1 a3159 1 .Nx 10 , @ 1.240 log @sh.1: replace triple negation with single negation, fix typo @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.239 2021/11/20 01:52:51 kre Exp $ d544 1 a544 1 In a non-interactive shell this option only has an effect if the d546 1 a546 1 option is set. @ 1.239 log @ Improve the wording of the "Argument List Processing" section (where all the sh options, also used with "set", are listed) in response to a discussion on icb conveyed to me by Darrin B. Jewell. A few improvements to the description of the "set" built-in as well. Bump Dd to cover all of this month's changes (so far). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.238 2021/11/16 23:39:34 rillig Exp $ d496 1 a496 1 Perhaps ocassionally useful for some debugging. d544 1 a544 2 In a non-interactive shell this option has no effect unless the @ 1.238 log @sh.1: fix typos @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.237 2021/11/16 11:28:29 kre Exp $ d34 1 a34 1 .Dd October 31, 2021 d269 3 d278 9 d386 10 d414 1 a414 1 Turn on job control (set automatically when interactive). d467 1 a467 1 flag being set does not cause the shell to be interactive. d496 1 a496 1 Useful for debugging. d528 11 d544 8 a551 1 In a non-interactive shell this option has no effect. d3622 4 a3625 1 .It Ic set Oo { Fl options | Cm +options | Cm \-- } Oc Ar arg ... d3630 3 a3632 1 With no arguments, it lists the values of all shell variables. d3652 5 a3656 1 In addition to the options listed there, d3679 2 a3680 2 parameters without changing any options, use .Dq -\|- d3695 2 @ 1.237 log @PR bin/56491 Make "hash" exit(!=0) (ie: exit(1)) if it writes an error message to stderr as required by POSIX (it was writing "not found" errors, yet still doing exit(0)). Whether, when doing "hash foobar", and "foobar" is not found as a command (not a built-in, not a function, and not found via a PATH search), that should be considered an error differs between shells. All of the ksh descendant shells say "no", write no error message in this case, and exit(0) if no other errors occur. Other shells (essentially all) do consider it an error, write a message to stderr, and exit(1) when this happens. POSIX isn't clear, the bug report: https://austingroupbugs.net/view.php?id=1460 which is not yet resolved, suggests that the outcome will be that this is to be unspecified. Given the diversity, there might be no other choice. Have a foot in both camps - default to the "other shell" behaviour, but add a -e option (no errors ... applies only to these "not found" errors) to generate the ksh behaviour. Without other errors (like an unknown option, etc) "hash -e anyname" will always exit(0). See the PR for details on how it all works now, or read the updated man page. While here, when hash is in its other mode (reporting what is in the table) check for I/O errors on stdout, and exit(1) (with an error message!) if any occurred. This does not apply to output generated by the -v option when command names are given (that output is incidental). In sh.1 document all of this. Also add documentation for a bunch of other options the hash command has had for years, but which were never documented. And while there, clean up some other sections I noticed needed improving (either formatting or content or both). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.236 2021/10/31 02:12:08 kre Exp $ d2370 1 a2370 1 (bad options, excess or insufficient number of args, etc). d2573 1 a2573 1 Then parse and execute the command resulting. d3029 1 a3029 1 oprions control which entries are printed. d3116 1 a3116 1 To allow a method to premit backwards compatability with the way d3120 1 a3120 1 .Nx 10 @ 1.236 log @PR bin/45390 Be explicit about what happens to PWD after a successful cd command. Also be very clear that "cd" and "cd -P" are the same thing, and the only cd variant implemented. Also, when it is appropriate to print the new directory after a cd command, note that it happens if interactive (as it always has here) and also if the posix option is set (for POSIX compat, where "interactive" is irrelevant). Mention that "cd -" is a case where the new directory is printed (along with paths relative to a non-empty CDPATH entry, and where the "cd old new" (string replacement in curdir) is used. While here document the new -e option to cd. XXX pullup -9 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.235 2021/10/26 00:05:38 kre Exp $ d2359 1 a2359 1 This section lists the built-in commands which are built-in because they d2369 4 d2377 2 a2378 1 Any arguments or redirects are evaluated, then ignored. d2435 2 a2436 1 that guarantees to find all the standard utilities. d2438 5 a2442 3 Do not execute the command but search for the command and print the resolution of the command search. d2447 6 a2452 3 Do not execute the command but search for the command and print the absolute pathname of utilities, the name for built-ins or the expansion of aliases. d2464 1 a2464 1 in the current directory name with d2479 3 a2481 1 is set and the directory name does not begin with a slash, d2485 2 a2486 1 will be searched for the specified directory. d2537 2 a2538 2 with the logical path and to change the current directory accordingly. d2546 1 a2546 1 directory that it actually switched to d2559 1 a2559 1 .\" or because a symbolic link was crossed. XXX Definitively not. d2570 7 a2576 2 Concatenate all the arguments with spaces. Then re-parse and execute the command. d2612 1 a2612 1 (perhaps the same d2614 1 a2614 1 as opened it, after the open) d2646 2 a2647 1 (exclude) the specified names are marked not to be exported, d2656 1 a2656 1 export -x FOO # FOO will now not be exported by default d2658 3 d2663 1 a2663 1 .Pp d2990 1 a2990 1 .It Ic hash Oo Fl rv Oc Op Ar command ... d2992 4 a2995 2 locations of commands. With no arguments whatsoever, d2998 53 a3050 2 command prints out the contents of this table. Entries which have not been looked at since the last d3055 19 a3073 1 With arguments, the d3076 2 a3077 1 they are functions) and then locates them. d3080 3 a3082 1 option, hash prints the locations of the commands as it finds them. d3084 45 a3128 3 .Fl r option causes the hash command to delete all the entries in the hash table except for functions. a3451 3 The environment variable .Ev PWD is set to the printed value. @ 1.235 log @PR bin/56464 After almost 30 years, finally do the right thing and read $HOME/.profile rather than .profile in the initial directory (it was that way in version 1.1 ...) All other ash descendants seem to have fixed this long ago. While here, copy a feature from FreeBSD which allows "set +p" (if a shell run by a setuid process with the -p flag is privileged) to reset the privileges. Once done (the set +p) it cannot be undone (a later set -p sets the 'p' flag, but that's all it does) - that just becomes a one bit storage location. We do this, as (also copying from FreeBSD, and because it is the right thing to do) we don't run .profile in a privileged shell - FreeBSD run /etc/suid_profile in that case (not a good name, it also applies to setgid shells) but I see no real need for that, we run /etc/profile in any case, anything that would go in /etc/suid_profile can just go in /etc/profile instead (with suitable guards so the commands only run in priv'd shells). One or two minor DEBUG mode changes (notably having priv'd shells identify themselves in the DEBUG trace) and sh.1 changes with doc of the "set +p" change, the effect that has on $PSc and a few other wording tweaks. XXX pullup -9 (not -8, this isn't worth it for the short lifetime that has left - if it took 28+ years for anyone to notice this, it cannot be having all that much effect). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.234 2021/09/15 18:30:57 kre Exp $ d34 1 a34 1 .Dd October 25, 2021 d86 1 a86 4 The current version of .Nm is in the process of being changed to conform more closely to the POSIX 1003.2 and 1003.2a specifications for the shell. d2445 1 a2445 1 .It Ic cd Oo Fl P Oc Op Ar directory Op Ar replace d2480 18 a2497 1 option instructs the shell to update d2499 10 a2508 2 with the specified physical directory path and change to that directory. This is the default. d2510 4 a2513 1 When the directory changes, the variable d2515 3 a2517 1 is set to the working directory before the change. d2527 3 a2529 1 In an interactive shell, the d2532 5 a2536 1 directory that it actually switched to if this is different from the name d2538 1 a2538 1 or always if the d2541 2 a2542 1 The destination may be different either because the d2544 3 a2546 3 mechanism was used .\" or because a symbolic link was crossed. or if the d2548 5 a2552 1 argument was used. @ 1.234 log @Have the ulimit command watch for ulimit -n (alter number of available fds) and keep the rest of the shell aware of any changes. While here, modify 'ulimit -aSH' to print both the soft and hard limits for the resources, rather than just (in this case, as H comes last) the hard limit. In any other case when both S and H are present, and we're examining a limit, use the soft limit (just as if neither were given). No change for setting limits (both are set, unless exactly one of -H or -S is given). However, we now check for overflow when converting the value to be assigned, rather than just truncating the value however it happens to work out... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.233 2021/09/12 06:53:08 wiz Exp $ d34 1 a34 1 .Dd September 11, 2021 d320 1 a320 1 if it has been set). d371 1 a371 1 (Not implemented.) d407 1 d413 8 d426 3 a428 2 options have been set, do not apply them when reading initialization files, these being d471 1 a471 1 if it has been set). d4451 1 a4451 1 is Output, after expansion like d4468 10 d4804 4 @ 1.233 log @Mark up NULL with Dv. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.232 2021/09/12 02:20:36 kre Exp $ d3723 6 a3728 1 If both are specified, the last one wins. d3734 3 a3736 1 show all the current limits @ 1.232 log @ Improve the formatting of the list of Built-in commands for those commands with multiple synopsis lines (eg: trap). But there really must be a better way to achieve this effect than the way it is accomplished here, and I'm hoping some wizard who understands mdoc much better than I do will revert this change and do it using some inspired magic incantation instead. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.231 2021/09/12 01:30:41 kre Exp $ d3035 3 a3037 1 is called with a NULL format. @ 1.231 log @ Don't dereference NULL on "jobs -Z" (with no title given), instead do setproctitle(NULL) (which is not the same thing at all). Do the same with jobs -Z '' as setting the title to "sh: " isn't useful. Improve the way this is documented, and note that it is only done this way because zsh did it first (ie: pass on the balme, doing this in the jobs command is simply absurd.) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.230 2021/09/11 20:43:32 christos Exp $ d2362 2 a2363 1 .Bl -tag -width 5n d2368 1 d2389 1 d2408 1 d2413 1 d2437 1 d2506 1 d2511 1 d2555 1 d2563 1 d2679 1 d2772 1 d2778 1 d2816 1 d2918 1 d2943 1 d2950 1 d2997 1 d3053 1 d3252 1 d3294 1 d3326 1 d3376 1 d3395 1 d3461 1 d3476 1 d3503 1 d3537 1 d3557 1 d3689 1 d3701 1 d3769 2 d3779 2 d3788 2 d3831 1 @ 1.230 log @Add jobs -Z (like in zsh(1)) to setproctitle(3). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.229 2020/09/18 07:21:26 wiz Exp $ d2980 2 a2981 1 .It Ic jobs Oo Fl l Ns \&| Ns Fl p \&| Fl Z Oc Op Ar job ... d3013 7 d4747 8 @ 1.229 log @Remove superfluous Ed. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.228 2020/09/18 06:48:28 kre Exp $ d34 1 a34 1 .Dd September 18, 2020 d2980 1 a2980 1 .It Ic jobs Oo Fl l Ns \&| Ns Fl p Oc Op Ar job ... d3008 5 @ 1.228 log @ Correct an incorrectly quoted (unquoted, but should be) example used in the "local" built-in command description (pointed out by mrg@@ via uwe@@ in private e-mail). Add a description to the export command of why this quoting is required, and then refer to it from local and readonly (explained in export as that one comes first). Note that some shells parse export/local/readonly (and often more) as "declarative" commands, and this quoting isn't needed (provided the command name is literal and not the result of an expansion) making X=$Y type args not require quoting, as they often don't in a regular variable assignment (preceding, or not part of, another command). POSIX is going to allow, but not require, that behaviour. We do not implement it. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.227 2020/08/25 19:42:02 kre Exp $ a2620 1 .Ed @ 1.227 log @ Idiot typo, generated by an idiot, fixed by the same one. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.226 2020/08/21 08:14:45 wiz Exp $ d34 1 a34 1 .Dd August 20, 2020 d2594 29 d3092 3 a3094 2 .Pp .Dl "local -N X=${X}" d3097 4 a3100 2 .Pp .Dl "local -N X=old-value-of-X" d3304 4 @ 1.226 log @Remove unmatched .El and mark up signal name with Dv. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.225 2020/08/20 23:19:34 kre Exp $ d1864 1 a1864 1 .Dv $ \" $@@ @ 1.225 log @ Man page enhancements. Better describe the command search procedure. Document "trap -P" Describe what works as a function name. More accurate description of reserved word recognition. Be more accurate about when field splittng happens after expansions (and in particular note that tilde expansions are not subject to field splitting). Be clear that "$@@" is not field split, it simply produces multiple fields as part of its expansion (hence IFS is irrelevant to this), but if used as $@@ (unquoted) each field produced is potentially subject to field splitting. Other minor wording changes. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.224 2020/02/20 18:24:20 pgoyette Exp $ a1135 1 .El d3586 3 a3588 1 Parse and execute the action that would be invoked were a SIGQUIT received. @ 1.224 log @Typo: s/./,/ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.223 2019/04/22 04:10:33 kre Exp $ d34 1 a34 1 .Dd February 20, 2020 d818 5 a822 2 shell and are recognized at the beginning of a line and after a control operator. d1114 11 a1124 10 When locating a command, the shell first looks to see if it has a shell function by that name. Then it looks for a built-in command by that name. If a built-in command is not found, one of two things happen: .Bl -enum .It Command names containing a slash are simply executed without performing any searches. .It Otherwise, the shell searches each entry in d1548 28 a1575 1 installs a function named name and returns an exit status of zero. d1782 3 a1784 1 Arithmetic Expansion (these all occur at the same time). d1786 3 d1790 1 a1790 3 generated by step (1) unless the .Ev IFS variable is null. d1858 9 a1866 2 expansion, with the exception of the special rules for .Dv @@ . \" $@@ d3485 2 a3486 1 .It Ic trap Oo Fl p Oc Ar signal ... d3547 6 d3555 1 a3555 1 provided they appear as the sole, or first, command in that sub-shell, d3585 4 @ 1.223 log @ Bump date for previous. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.222 2019/04/22 04:04:35 kre Exp $ d34 1 a34 1 .Dd April 22, 2019 d4439 1 a4439 1 integer value. and can be expanded using any of the forms @ 1.223.2.1 log @Pull up following revision(s) (requested by kre in ticket #1371): bin/sh/main.c: revision 1.87 bin/sh/main.c: revision 1.88 bin/sh/memalloc.h: revision 1.20 bin/sh/sh.1: revision 1.235 bin/sh/memalloc.c: revision 1.34 bin/sh/memalloc.c: revision 1.35 bin/sh/memalloc.h: revision 1.19 bin/sh/shell.h: revision 1.31 bin/sh/options.c: revision 1.56 PR bin/56464 After almost 30 years, finally do the right thing and read $HOME/.profile rather than .profile in the initial directory (it was that way in version 1.1 ...) All other ash descendants seem to have fixed this long ago. While here, copy a feature from FreeBSD which allows "set +p" (if a shell run by a setuid process with the -p flag is privileged) to reset the privileges. Once done (the set +p) it cannot be undone (a later set -p sets the 'p' flag, but that's all it does) - that just becomes a one bit storage location. We do this, as (also copying from FreeBSD, and because it is the right thing to do) we don't run .profile in a privileged shell - FreeBSD run /etc/suid_profile in that case (not a good name, it also applies to setgid shells) but I see no real need for that, we run /etc/profile in any case, anything that would go in /etc/suid_profile can just go in /etc/profile instead (with suitable guards so the commands only run in priv'd shells). One or two minor DEBUG mode changes (notably having priv'd shells identify themselves in the DEBUG trace) and sh.1 changes with doc of the "set +p" change, the effect that has on $PSc and a few other wording tweaks. XXX pullup -9 (not -8, this isn't worth it for the short lifetime that has left - if it took 28+ years for anyone to notice this, it cannot be having all that much effect). Use a type-correct end marker for strstrcat() rather than NULL, as for a function with unknown number & types of args, the compiler isn't able to automatically convert to the correct type. Issue pointed out in off list e-mail by Rolland Illig ... Thanks. The first arg (pointer to where to put length of result) is of a known type, so doesn't have the same issue - we can keep using NULL for that one when the length isn't needed. Also, make sure to return a correctly null terminated null string in the (absurd) case that there are no non-null args to strstrcat() (though there are much better ways to generate "" on the stack). Since there is currently just one call in the code, and it has real string args, this isn't an issue for now, but who knows, some day. NFCI - if there is any real change, then it is a change that is required. XXX pullup -9 (together with the previous changes) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.223 2019/04/22 04:10:33 kre Exp $ d34 1 a34 1 .Dd October 25, 2021 d320 1 a320 1 if it had been set). d371 1 a371 1 (Obsolete and not implemented.) a406 1 The same applies to effective and real GIDs. a411 8 This option is effective only when set on the command line, but can be reset to drop privileges, once, at any time. If .Fl p is cleared, those privileges can never be regained, however much the .Fl p option is manipulated. d417 2 a418 3 options have been set, temporarily disable them before reading initialization files, these being d461 1 a461 1 if it had been set). d4293 1 a4293 1 is output, after expansion as described for a4309 10 If a privileged shell has its privileges removed by clearing the .Fl p option, an attempt will be made to be reset .Ev PSc to .Dq \&# or .Dq \&$ , as appropriate for its new privilege level. a4635 4 This .Nx .Nm is a much modified descendant of the ash shell written by Ken Almquist. @ 1.223.2.2 log @Pull up following revision(s) (requested by kre in ticket #1372): bin/sh/sh.1: revision 1.236 (patch) bin/sh/cd.c: revision 1.51 PR bin/45390 - fix for folly four In the pwd builtin, verify that curdir names '.' before simply printing it. Never alter PWD or OLDPWD in the pwd command. Also while here, implement the (new: coming in POSIX, but has existed for a while in several other shells) -e option to cd (with -e, cd -P will exit(1) if the chdir() succeeds, but PWD cannot be discovered). cd now prints the directory name used (if different from that given, or cdprint is on) if interactive or (the new bit)in posix mode. Some additional/changed comments added, and a DEBUG mode trace call that was accidentally put inside an #if 0 block moved to where it can do some good. XXX pullup -9 PR bin/45390 Be explicit about what happens to PWD after a successful cd command. Also be very clear that "cd" and "cd -P" are the same thing, and the only cd variant implemented. Also, when it is appropriate to print the new directory after a cd command, note that it happens if interactive (as it always has here) and also if the posix option is set (for POSIX compat, where "interactive" is irrelevant). Mention that "cd -" is a case where the new directory is printed (along with paths relative to a non-empty CDPATH entry, and where the "cd old new" (string replacement in curdir) is used. While here document the new -e option to cd. XXX pullup -9 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.223.2.1 2021/11/06 13:35:43 martin Exp $ d34 1 a34 1 .Dd October 31, 2021 d86 4 a89 1 It is a re-implementation and extension of the Bourne shell. d2402 1 a2402 1 .It Ic cd Oo Fl Pe Oc Op Ar directory Op Ar replace d2437 1 a2437 18 option (which is the unalterable default in this .Nm ) instructs the shell to change to the directory specified (or determined) and if successful update .Ev PWD with the new physical directory path. That is the path name, not traversing any symbolic links, of the altered working directory of the shell. .Pp The .Fl e option alters the interpretation of the exit status. .Ic cd will exit with status 0 if successful. If the directory was successfully changed, but d2439 2 a2440 10 was unable to be updated, .Ic cd will exit with status 1 if the .Fl e option was given, and status 0 otherwise. Upon any other error, including usage errors, and failing to successfully change directory, .Ic cd will exit with status 2. d2442 1 a2442 4 When the directory changes, and .Ev PWD is updated, the variable d2444 1 a2444 3 is set to the working directory .Po \&\$ Ns Ev PWD Ns Pc as it was before the change. d2454 1 a2454 3 In an interactive shell, or if the .Cm posix option is set, the d2457 1 a2457 5 directory that it actually switched to .Po that is, the pathname passed to the successful .Xr chdir 2 .No system call Pc if this is different from the name d2459 1 a2459 1 or if the d2462 1 a2462 2 The destination may be different because a non-empty element of the d2464 3 a2466 3 mechanism was used, .\" or because a symbolic link was crossed. XXX Definitively not. or because the d2468 1 a2468 5 argument was used, or because the .Ar directory parameter was specified as .Dq \&\- . @ 1.222 log @ PR standards/40554 Update the description of the <& and >& redirection operators (as indicated would happen in a message appended to the PR a week ago, which received no opposition - no feedback). Some rewriting of the section on redirects (including how the word expansion of the "file" works) to make this simpler & more accurate. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.221 2019/04/15 20:35:25 uwe Exp $ d34 1 a34 1 .Dd February 14, 2019 @ 1.221 log @-compact must come last @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.220 2019/02/14 11:15:24 kre Exp $ d910 2 a911 1 The following is a list of the possible redirections. d917 1 a917 1 .Li [3] ) , d919 1 a919 1 If present it must occur immediately before the redirection d922 24 d966 2 a967 2 .It Oo Ar n1 Oc Ns Ic <& Ns Ar n2 Duplicate standard input (or d969 1 a969 1 from file descriptor d971 1 a971 3 .Ar n2 is expanded if not a digit string, the result must be a number. .It Oo Ar n Oc Ns Ic <&- d974 14 a987 2 .It Oo Ar n1 Oc Ns Ic >& Ns Ar n2 Duplicate standard output (or d989 1 a989 1 to d991 1 a991 1 .It Oo Ar n Oc Ns Ic >&- @ 1.220 log @ Add the "specialvar" built-in command. Discussed (well, mentioned anway) on tech-userlevel with no adverse response. This allows the magic of vars like HOSTNAME SECONDS, ToD (etc) to be restored should it be lost - perhaps by having a var of the same name imported from the environment (which needs to remove the magic in case a set of scripts are using the env to pass data, and the var name chosen happens to be one of our magic ones). No change to SMALL shells (or smaller) - none of the magic vars (except LINENO, which is exempt from all of this) exist in those, hence such a shell has no need for this command either. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.219 2019/02/04 12:18:36 wiz Exp $ d4113 1 a4113 1 .Bd -compact -literal -offset indent @ 1.219 log @Remove leading zero from date. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.218 2019/02/04 11:16:41 kre Exp $ d34 1 a34 1 .Dd February 4, 2019 d3354 33 d4129 3 d4151 3 d4326 3 d4363 3 @ 1.218 log @PR bin/53919 Suppress shell error messages while expanding $ENV (which also causes errors while expanding $PS1 $PS2 and $PS4 to be suppressed as well). This allows any random garbage that happens to be in ENV to not cause noise when the shell starts (which is effectively all it did). On a parse error (for any of those vars) we also use "" as the result, which will be a null prompt, and avoid attempting to open any file for ENV. This does not in any way change what happens for a correctly parsed command substitution (either when it is executed when permitted for one of the prompts, or when it is not (which is always for ENV)) and commands run from those can still produce error output (but shell errors remain suppressed). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.217 2019/01/21 14:09:24 kre Exp $ d34 1 a34 1 .Dd February 04, 2019 @ 1.217 log @ Add an explanation of the error (warning) RANDOM initialisation failed when the shell might print after RANDOM has been reseeded (which includes at sh startup) the next time RANDOM is accessed. It indicates that /dev/urandom was not available or did not provide data - in that case, sh uses a (weak) seed made out of the pid and time (but otherwise nothing else changes). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.216 2018/12/12 20:22:43 kre Exp $ d34 1 a34 1 .Dd December 12, 2018 d132 3 d155 8 a162 2 and then reads commands from the file name that results. If d164 3 a166 3 contains a command substitution, or one of the other expansions fails, or if there are no expansions to expand, the value of d4072 5 a4121 1 See the d4204 7 a4210 2 For other expansion errors, a message will be output, and the unexpanded string will then be used as the prompt. d4219 1 a4219 1 Output, after expansion like d4221 1 a4221 1 before each line when execution trace @ 1.216 log @Reverse a decision made when the printsignals() routines from kill and sh were merged so that the shell (for trap -l) and kill (for kill -l) can use the same routine, and site that function in the shell, rather than in kill (use the code that is in kill as the basis for that routine). This allows access to sh internals, and in particular to the posix option, so the builtin kill can operate in posix mode where the standard requires just a single character (space of newline) between successive signal names (and we prefer nicely aligned columns instead).. In a SMALL shell, use the ancient sh printsignals routine instead, it is smaller (and very much dumber). /bin/kill still uses the routine that is in its source, and is not posix compliant. A task for some other day... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.215 2018/12/12 12:56:17 kre Exp $ d4257 8 @ 1.215 log @ More fixes for the SYNPOSIS of the readonly built-in. The SYNOPSIS for "readonly -q" cannot have the -q be optional ... Also harmonise the output appearance with that of the export command. wiz: have at it... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.214 2018/12/12 12:30:59 kre Exp $ d533 5 d542 1 a542 1 .Dq "{ }" @ 1.214 log @ Fix Oo Op Oc syntax error (which seemed to work OK to me....) Pointed out by wiz@@ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.213 2018/12/12 11:51:33 kre Exp $ d3172 3 a3174 3 .It Ic readonly Ar name Ns Oo =value Oc Ns ... .It Ic readonly Oo Fl p Oo name... Oc Oc .It Ic readonly Oo Fl q Oc name... @ 1.213 log @Implement: readonly -q VAR... readonly -p VAR... export -q [-x] VAR... export -p [-x] VAR... all available only in !SMALL shells - and while here, limit "export -x" to full sized shells as well. Also, do a better job of arg checking and validating of the export and readonly commands (which is really just one built-in) and of issuing error messages when something bogus is detected. Since these commands are special builtin commands, any error causes shell exit (for non-interactive shells). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.212 2018/12/11 13:31:20 kre Exp $ d3173 1 a3173 1 .It Ic readonly Oo Fl p Op name... Oc @ 1.212 log @PR standards/42829 Implement parameter and arithmetic expansion of $ENV before using it as the name of a file from which to read startup commands for the shell. This continues to happen for all interactive shells, and non-interactive shells for which the posix option is not set (-o posix). On any actual error, or if an attempt is made to use command substitution, then the value of ENV is used unchanged as the file name. The expansion complies with POSIX XCU 2.5.3, though that only requires parameter expansion - arithmetic expansion is an extension (but for us, it is much easier to do, than not to do, and it allows some weird stuff, if you're so inclined....) Note that there is no ~ expansion (use $HOME). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.211 2018/12/04 14:03:30 kre Exp $ d34 1 a34 1 .Dd December 11, 2018 d2277 1 d2297 1 d2315 1 d2319 1 d2342 1 d2410 1 d2414 1 d2457 1 d2464 4 a2467 2 .It Ic export Oo Fl npx Oc Ar name ... .It Ic export Fl p Op Fl x d2490 1 d2501 1 a2501 1 same time it is exported by writing d2503 1 a2503 1 .Dl export name=value d2505 2 a2506 1 With no arguments the export command lists the names of all exported variables, d2509 1 a2509 1 was given, all variables marked not for export. d2512 6 a2517 1 option specified the output will be formatted suitably for non-interactive use. d2519 15 a2533 1 The d2536 1 a2536 2 unless an invalid option, or option combination, is given, or unless an attempt is made to export a variable which has d2539 7 d2550 2 a2551 1 and creating it again \(en provided it is not also read-only. d2643 1 d2648 1 d2685 1 d2786 1 d2810 1 d2816 1 d2862 1 d2904 1 d3099 1 d3140 1 d3171 6 a3176 3 .It Ic readonly Ar name ... .It Ic readonly Op Fl p The specified names are marked as read only, so that they cannot be d3185 1 a3185 1 command lists the names of all read only variables. d3188 29 a3216 1 option specified the output will be formatted suitably for non-interactive use. d3234 1 d3299 1 d3313 1 d3339 1 d3358 1 d3476 1 d3487 1 d3610 1 @ 1.211 log @Alter a design botch when magic (self modifying) variables were added to sh ... in other shells, setting such a variable (for most of them) causes it to lose its special properties, and act the same as any other variable. I had assumed that was just implementor laziness... I was wrong. From now on the NetBSD shell will act like the others, and if vars like HOSTNAME (and SECONDS, etc) are used as variables in a script or whatever, they will act just like normal variables (and unless this happens when they have been made local, or as a variable-assignment as a prefix to a command, the special properties they would have had otherwise are lost for the remainder of the life of the (sub-)shell in which the variables were set). Importing a value from the environment counts as setting the value for this purpose (so if HOSTNAME is set in the environment, the value there will be the value $HOSTNAME expands to). The two exceptions to this are LINENO and RANDOM. RANDOM needs to be able to be set to (re-)set its seed. LINENO needs to be able to be set (at least in the "local" command) to achieve the desired functionality. It is unlikely that any (sane) script is going to want to use those two as normal vars however. While here, fix a minor bug in popping local vars (fn return) that need to notify the shell of changes in value (like PATH). Change sh(1) to reflect this alteration. Also add doc of the (forgotten) magic var EUSER (which has been there since the others were added), and add a few more vars (which are documented in other places in sh(1) - like ENV) into the defined or used variable list (as well as wherever else they appear). XXX pullup -8 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.210 2018/12/03 06:43:19 kre Exp $ d34 1 a34 1 .Dd December 4, 2018 d136 2 d148 13 a160 3 the shell next reads commands from the file named in .Ev ENV . d282 2 a283 1 while this flag is set. d658 2 a659 1 the two characters, escape and newline, are removed from the input string. @ 1.210 log @Cleanup traps a bit - attempt to handle weird uses in traps, such as traps that issue break/continue/return to cause the loop/function executing when the trap occurred to break/continue/return, and generating the correct exit code from the shell including when a signal is caught, but the trap handler for it exits. All that from FreeBSD. Also make T=$(trap) work as it is supposed to (also trap -p). For now this is handled by the same technique as $(jobs) - rather than clearing the traps in subshells, just mark them invalid, and then whenever they're invalid, clear them before executing anything other than the special blessed "trap" command. Eventually we will handle these using non-subshell command substitution instead (not creating a subshell environ when the commands in a command-sub alter nothing in the environment). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.209 2018/11/23 20:40:06 kre Exp $ d34 1 a34 1 .Dd May 3, 2018 d2998 15 d3952 24 d3994 1 a3994 2 Setting it does nothing except reverse the effect of an earlier .Ic unset . d4046 16 a4152 1 Attempts to set this variable are ignored. d4154 1 d4166 1 a4166 1 is not unset. d4188 1 a4188 2 Setting it has no effect, other than to reverse the effect of an earlier .Ic unset . @ 1.209 log @ Avoid long option names that differ only in character case. Change Xtrace (the name) to xlock instead. Aside from the different name, there is no change to functionality. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.208 2018/09/04 23:16:30 kre Exp $ d3310 5 a4378 15 The .Ic trap command cannot usefully be used, yet, within a command substitution, to obtain the current trap values, as all command substitutions are currently executed within a sub-shell environment, and in sub-shells all non-ignored, non-default, traps are reset. As a workaround, it is possible to redirect output from .Dq trap or .Dq trap -p to a file, and then read the file later using the .Dq \&. command. .Pp @ 1.208 log @Change the way the pipefail option works. Now it is the setting of the option when a pipeline is created that controls the way the exit status of the pipeline is calculated. Previously it was the state of the option when the exit status of the pipeline was collected. This makes no difference at all for foreground pipelines (there is no way to change the option between starting and completing the pipeline) but it does for asynchronous (background) pipelines. This was always the right way to implement it - it was originally done the other way as I could not find any other shell implemented this way - they all seemed to do it our previous way, and I could not see a good reason to be the sole different shell. However, now I know that ksh93 works as we will now work, and I am told that if the option is added to the FreeBSD shell (apparently the code exists, uncommitted) it will be the same. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.207 2018/08/25 17:35:31 kre Exp $ d446 1 a446 1 .It Fl X Em Xtrace @ 1.207 log @ PR bin/48875 Add a paragraph (briefer than previously posted to mailing lists) to explain that there is no guarantee that the results of a command substitution will be available before all commands started by the cmdsub have completed. Include the original proposed text (much longer) as *roff comments, so it will at least be available to those who browse the man page sources. While here, clean up the existing text about command substitutions to make it a little more accurate (and to advise against using the `` form). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.206 2018/05/03 05:11:43 wiz Exp $ d491 2 a492 1 If set, the way the exit status of a pipeline is determined d1159 5 a1163 5 option is set when the pipeline completes and its status is collected, the pipeline status is the status of the last (rightmost) command in the pipeline to exit with non-zero exit status, or zero, if, and only if, all commands in the pipeline exited with a status of zero. d1166 1 a1166 1 option is not set, which is the default state, d1168 1 a1168 1 status of the last command in the pipeline, @ 1.206 log @Remove Pps without effect. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.205 2018/05/03 00:32:11 kre Exp $ d1906 2 a1907 1 Command substitution occurs when the command is enclosed as follows: d1909 1 a1909 1 .Dl Ic $( Ns Ar command Ns Ic \&) d1911 17 a1927 11 or .Po .Dq backquoted version .Pc : .Pp .Dl Ic \&` Ns Ar command Ns Ic \&` .Pp The shell expands the command substitution by executing command in a sub-shell environment and replacing the command substitution with the standard output of the command, removing sequences of one or more d1929 1 a1929 1 at the end of the substitution. d1934 2 a1935 2 they may be translated into .Ao space Ac Ns s , d1939 85 @ 1.206.2.1 log @Sync with HEAD @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.223 2019/04/22 04:10:33 kre Exp $ d34 1 a34 1 .Dd April 22, 2019 a131 3 (as if by using the .Dq \&. command) a135 2 in the user's home directory .Pq \&$HOME , d146 3 a148 19 the shell then performs parameter and arithmetic expansion on the value of .Ev ENV , (these are described later) and if no errors occurred, then reads commands from the file name that results. Note that no error messages result from these expansions, to verify that .Ev ENV is correct, as desired, use: .Dl eval printf '%s\e\en' Dq \&${ENV} Otherwise if .Ev ENV appears to contain a command substitution, which is not performed here, or if there were no expansions to expand, the value of .Ev ENV is used as the file name. .Pp d270 1 a270 2 while this flag is set, unless the variable has been marked as not for export. d446 1 a446 1 .It Fl X Em xlock d491 1 a491 2 If set when a pipeline is created, the way the exit status of the pipeline is determined a518 5 the format of the output of the .Ic kill Fl l command, where posix mode causes the names of the signals be separated by either a single space or newline, and where otherwise sufficient spaces are inserted to generate nice looking columns, d523 1 a523 1 .Dq "{\ }" d644 1 a644 2 the two characters, the backslash escape and the newline, are removed from the input string. d881 1 a881 2 A list of the possible redirections, and their meanings, follows. .Pp d887 1 a887 1 .Sq Li [3] ) , d889 1 a889 1 If present it must occur unquoted, immediately before the redirection a891 24 If file descriptor .Ar n was open prior to the redirection, its previous use is closed. .Pp All redirections have a single word .Ar file argument following the operator (white space is allowed between the redirection operator and .Ar file ) , though it is sometimes expressed as .Ar n2 . That argument is expanded (see .Sx "Word Expansions" below) using tilde expansion, parameter expansion, arithmetic expansion, command substitution and quote removal to produce the path name (or file descriptor) to be used. No field splitting or pathname expansion takes place. In the list below, where the .Ar file is given as .Ar n2 the result of the expansions must be a number which refers to a suitable open file descriptor. d912 2 a913 2 .It Oo Ar n1 Oc Ns Ic <& Ar n2 Redirect standard input (or d915 1 a915 1 from a duplicate of file descriptor d917 3 a919 1 .It Oo Ar n Oc Ns Ic <& \(mi d922 2 a923 14 Note that the .Sq \&\(mi is minus sign (or hyphen) given literally or resulting from the expansion of .Ar file (or .Ar n2 ) for this format. When given literally there is usually no space between the redirection operator and the .Sq \&\(mi , though that is just a convention. .It Oo Ar n1 Oc Ns Ic >& Ar n2 Redirect standard output (or d925 1 a925 1 to be a duplicate of d927 1 a927 1 .It Oo Ar n Oc Ns Ic >& \(mi d1158 5 a1162 5 option was set when a pipeline was started, the pipeline status is the status of the last (lexically last, i.e.: rightmost) command in the pipeline to exit with non-zero exit status, or zero, if, and only if, all commands in the pipeline exited with a status of zero. d1165 1 a1165 1 option was not set, which is the default state, d1167 1 a1167 1 status of the last (rightmost) command in the pipeline, d1906 1 a1906 2 Command substitution occurs when a word contains a command list enclosed as follows: d1908 1 a1908 1 .Dl Ic $( Ns Ar list Ns Ic \&) d1910 11 a1920 17 or the older .Pq Dq backquoted version, which is best avoided: .Pp .Dl Ic \&` Ns Ar list Ns Ns Ic \&` .Pp See the section .Sx Complex Commands above for the definition of .Ic list . .Pp The shell expands the command substitution by executing the .Ar list in a sub-shell environment and replacing the command substitution with the standard output of the .Ar list after removing any sequence of one or more d1922 1 a1922 1 from the end of the substitution. d1927 2 a1928 2 they may be used to separate fields .Pq "as spaces usually are" a1931 85 .Pp Note that if a command substitution includes commands to be run in the background, the sub-shell running those commands will only wait for them to complete if an appropriate .Ic wait command is included in the command list. However, the shell in which the result of the command substitution will be used will wait for both the sub-shell to exit and for the file descriptor that was initially standard output for the command substitution sub-shell to be closed. In some circumstances this might not happen until all processes started by the command substitution have finished. .\" While the exit of the sub-shell closes its standard output, .\" any background process left running may still .\" have that file descriptor open. .\" This includes yet another sub-shell which might have been .\" (almost invisibly) created to wait for some other command to complete, .\" and even where the background command has had its .\" standard output redirected or closed, .\" the waiting sub-shell may still have it open. .\" Thus there is no guarantee that the result of a command substitution .\" will be available in the shell which is to use it before all of .\" the commands started by the command substitution have completed, .\" though careful coding can often avoid delays beyond the termination .\" of the command substitution sub-shell. .\" .Pp .\" For example, assuming a script were to contain the following .\" code (which could be done better other ways, attempting .\" this kind of trickery is not recommended): .\" .Bd -literal -offset indent .\" if [ "$( printf "Ready? " >&2; read ans; printf "${ans}"; .\" { sleep 120 >/dev/null && kill $$ >/dev/null 2>&1; }& )" = go ] .\" then .\" printf Working... .\" # more code .\" fi .\" .Ed .\" .Pp .\" the .\" .Dq Working... .\" output will not be printed, and code that follows will never be executed. .\" Nor will anything later in the script .\" .Po .\" unless .\" .Dv SIGTERM .\" is trapped or ignored .\" .Pc . .\" .Pp .\" The intent is to prompt the user, wait for the user to .\" answer, then if the answer was .\" .Dq go .\" do the appropriate work, but set a 2 minute time limit .\" on completing that work. .\" If the work is not done by then, kill the shell doing it. .\" .Pp .\" It will usually not work as written, as while the 2 minute .\" .Sq sleep .\" has its standard output redirected, as does the .\" .Sq kill .\" that follows (which also redirects standard error, .\" so the user would not see an error if the work were .\" completed and there was no parent process left to kill); .\" the sub-shell waiting for the .\" .Sq sleep .\" to finish successfully, so it can start the .\" .Sq kill , .\" does not. .\" It waits, with standard output still open, .\" for the 2 minutes until the sleep is done, .\" even though the kill is not going to need that file descriptor, .\" and there is nothing else which could. .\" The command substitution does not complete until after .\" the kill has executed and the background sub-shell .\" finishes \(en at which time the shell running it is .\" presumably dead. .\" .Pp .\" Rewriting the background sub-shell part of that as .\" .Dl "{ sleep 120 && kill $$ 2>&1; } >/dev/null &" .\" would allow this .\" .Nm .\" to perform as expected, but that is not guaranteed, .\" not all shells would behave as planned. .\" It is advised to avoid starting background processes .\" from within a command substitution. a2169 1 .\" a2188 1 .\" a2205 1 .\" a2208 1 .\" a2230 1 .\" a2297 1 .\" a2300 1 .\" a2342 1 .\" d2349 2 a2350 4 .\" .It Ic export Oo Fl nx Oc Ar name Ns Oo =value Oc ... .It Ic export Oo Fl x Oc Oo Fl p Oo Ar name ... Oc Oc .It Ic export Fl q Oo Fl x Oc Ar name ... a2372 1 export FOO # this command will fail (non-fatally) d2383 1 a2383 1 same time it is exported (or unexported, etc) by writing d2385 1 a2385 1 .Dl export [-nx] name=value d2387 1 a2387 2 With no arguments the export command lists the names of all set exported variables, d2390 1 a2390 1 was given, all set variables marked not for export. d2393 1 a2393 6 option specified, the output will be formatted suitably for non-interactive use, and unset variables are included. When .Fl p is given, variable names, but not values, may also be given, in which case output is limited to the variables named. d2395 1 a2395 15 With .Fl q and a list of variable names, the .Ic export command will exit with status 0 if all the named variables have been marked for export, or 1 if any are not so marked. If .Fl x is also given, the test is instead for variables marked not to be exported. .Pp Other than with .Fl q , the d2398 2 a2399 1 unless an attempt is made to export a variable which has a2401 7 In all cases if an invalid option, or option combination, is given, or an invalid variable name is present, .Ic export will write a message to the standard error output, and exit with a non-zero status. A non-interactive shell will terminate. d2406 1 a2406 2 and creating it again \(en provided the variable is not also read-only. .\" a2497 1 .\" a2501 1 .\" a2537 1 .\" a2637 1 .\" a2660 1 .\" a2665 1 .\" a2710 1 .\" a2751 1 .\" a2904 15 If any of the shell's magic variables (those which return a value which may vary without the variable being explicitly altered, e.g.: .Dv SECONDS or .Dv HOSTNAME ) are made local in a function, they will lose their special properties when set within the function, including by the .Ic local command itself (if not to be set in the function, there is little point in making a variable local) but those properties will be restored when the function returns. a2930 1 .\" a2970 1 .\" d3001 3 a3003 6 .\" .It Ic readonly Ar name Ns Oo =value Oc ... .It Ic readonly Oo Fl p Oo Ar name ... Oc Oc .It Ic readonly Fl q Ar name ... With no options, the specified names are marked as read only, so that they cannot be d3012 1 a3012 1 command lists the names of all set read only variables. d3015 1 a3015 29 option specified, the output will be formatted suitably for non-interactive use, and unset variables are included. When the .Fl p option is given, a list of variable names (without values) may also be specified, in which case output is limited to the named variables. .Pp With the .Fl q option, the .Ic readonly command tests the read-only status of the variables listed and exits with status 0 if all named variables are read-only, or with status 1 if any are not read-only. .Pp Other than as specified for .Fl q the .Ic readonly command normally exits with status 0. In all cases, if an unknown option, or an invalid option combination, or an invalid variable name, is given; or a variable which was already read-only is attempted to be set; the exit status will not be zero, a diagnostic message will be written to the standard error output, and a non-interactive shell will terminate. .\" a3032 1 .\" a3096 1 .\" a3109 1 .\" a3134 34 .\" .It Ic specialvar Ar variable ... For each .Ar variable name given, if the variable named is one which, in this .Nm , could be treated as a special variable, then cause that .Ar variable to be made special, undoing any effects of an earlier .Ic unset or assignment to the variable. If all .Ar variable Ns s given are recognized special variables in this .Nm the .Ic specialvar command will exit with status 0, otherwise 1. Invalid usage will result in an exit status of 2. .Pp Note that all variables capable of being special are created that way, this command is not required to cause that to happen. However should such a variable be imported from the environment, that will cause (for those special variables so designated) the special effects for that variable to be lost. Consequently, as the contents of the environment cannot be controlled, any script which desires to make use of the properties of most of the special variables should use this command, naming the variables required, to ensure that their special properties are available. .\" a3152 1 .\" a3216 5 These variants of the trap command may be executed in a sub-shell .Pq "such as in a command substitution" , provided they appear as the sole, or first, command in that sub-shell, in which case the state of traps from the parent of that sub-shell is reported. a3264 1 .\" a3274 1 .\" a3396 1 .\" a3838 32 .It Ev ENV Names the file sourced at startup by the shell. Unused by this shell after initialization, but is usually passed through the environment to descendant shells. See the .Sx Invocation section above for details of how .Ev ENV is processed and used. .It Ev EUSER Set to the login name of the effective user id running the shell, as returned by .Bd -literal -offset indent -compact getpwuid(geteuid())->pw_name .Ed .Po See .Xr getpwuid 3 and .Xr geteuid 2 for more details. .Pc This is obtained each time .Ev EUSER is expanded, so changes to the shell's execution identity cause updates without further action. If unset, it returns nothing. If set it loses its special properties, and is simply a variable. See the .Ic specialvar built-in command for remedial action. d3857 2 a3858 4 If set it loses its special properties, and is simply a variable. See the .Ic specialvar built-in command for remedial action. d3866 1 a3909 16 .It Ev POSIXLY_CORRECT If set in the environment upon initialization of the shell, then the shell option .Ic posix will be set. .Po See the description of the .Ic set command in the .Sx Built-ins section. .Pc After initialization it is unused by the shell, but is usually passed through the environment to descendant processes, including other instances of the shell, which may interpret it in a similar way. d3933 2 a3934 7 For other expansion errors, the prompt will become an empty string, without an error message. To verify parsing of .Ev PS1 , the method suggested for .Ev ENV can be used. d3943 1 a3943 1 is Output, after expansion like d3945 1 a3945 1 as a prefix for each line when execution trace a3998 8 Should the error message .Dq "RANDOM initialisation failed" appear on standard error, it indicates that the source of good random numbers was not available, and .Ev RANDOM has instead been seeded with a more predictable value. The following sequence of random numbers will not be as unpredictable as they otherwise would be. d4001 1 a4002 4 If set, it loses its special properties, and becomes a normal variable. See the .Ic specialvar built-in command for remedial action. d4014 1 a4014 1 has not been set or unset. d4036 2 a4037 4 If set, it loses its special properties, and becomes a normal variable. See the .Ic specialvar built-in command for remedial action. d4281 15 @ 1.206.2.2 log @Merge changes from current as of 20200406 @ text @d1 1 a1 1 .\" $NetBSD$ d34 1 a34 1 .Dd February 20, 2020 d4439 1 a4439 1 integer value, and can be expanded using any of the forms @ 1.206.2.3 log @Sync with HEAD @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.206.2.2 2020/04/08 14:03:04 martin Exp $ @ 1.206.2.4 log @Ooops, restore accidently removed files from merge mishap @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.224 2020/02/20 18:24:20 pgoyette Exp $ @ 1.205 log @ Simplify convoluted language, and remove incorrect statement (that I added a while ago) about what is required by POSIX. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.204 2018/05/02 21:43:38 pgoyette Exp $ a177 1 .Pp a3281 1 .Pp a3297 1 .Pp @ 1.204 log @Minor grammatical correction (don't end a sentence/phrase with a preposition). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.203 2018/03/17 01:53:06 uwe Exp $ d2324 1 a2324 1 unless the descriptors to which they point refer to the standard input, a2329 3 This behavior is required by the POSIX standard, so when the .Cm posix option is set, this shell also acts that way. @ 1.203 log @Drop "show or set the limit on" legalese from the description of each and every option to ulimit built-in. The show-or-set text is already supplied *both* before and after the list. Pedantically repeating it for each option just adds a lot of visual clutter that gets in the way of actually using this fragment of the manual page as a quick reference. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.202 2018/03/17 01:40:28 uwe Exp $ d34 1 a34 1 .Dd October 24, 2017 d2324 1 a2324 1 unless the descriptors they point to refer to the standard input, @ 1.202 log @Tweak "ulimit" synopsis. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.201 2018/03/17 01:32:42 uwe Exp $ d3286 1 d3303 1 d3308 1 a3308 1 show or set the limit on the socket buffer size of a process (in bytes) d3310 2 a3311 2 show or set the limit on the largest core dump size that can be produced (in 512-byte blocks) d3313 1 a3313 1 show or set the limit on the data segment size of a process (in kilobytes) d3315 2 a3316 2 show or set the limit on the largest file that can be created (in 512-byte blocks) d3318 1 a3318 1 show or set the limit on how much memory a process can lock with d3320 1 a3320 1 (in kilobytes) d3322 2 a3323 2 show or set the limit on the total physical memory that can be in use by a process (in kilobytes) d3325 1 a3325 1 show or set the limit on the number of files a process can have open at once d3327 1 a3327 1 show or set the limit on the number of processes this user can d3330 1 a3330 1 show or set the limit on the number of threads this user can d3333 1 a3333 1 show or set the limit on the stack size of a process (in kilobytes) d3335 1 a3335 1 show or set the limit on CPU time (in seconds) d3337 1 a3337 1 show or set the limit on how large a process address space can be @ 1.201 log @Cleanup markup in the "Command Line Editing" section. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.200 2018/03/17 01:03:08 uwe Exp $ d3279 1 a3279 1 .It Ic ulimit Oo Fl H \*(Ba Fl S Oc Op Fl a \*(Ba Fl btfdscmlrpnv Op Ar value d3291 2 a3298 1 .El @ 1.200 log @Cleanup markup in the "Job Control" section. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.199 2018/03/17 00:03:25 uwe Exp $ d3651 3 d3657 3 d3661 1 a3661 2 .Ar vi insert mode. d3666 1 a3666 3 The .Ar vi mode uses commands similar to a subset of those described in the d3674 1 a3674 1 .Xr vi 1 : d3677 1 a3677 1 key will throw you into command VI command mode. d3682 1 a3682 3 The .Ar emacs mode uses commands similar to a subset available in the d3695 1 a3695 5 and the default settings in .Ar emacs and .Ar vi modes. d3729 1 a3729 1 .Ev PSlit . d3733 1 a3733 1 .Ev PSlit d3740 1 a3740 1 .Ev PSlit d3742 1 a3742 1 .Ev PSlit d3746 1 a3746 1 .Ev PSlit d3752 1 a3752 1 .Ev PSlit d3757 1 a3757 1 .Ev PSlit d3760 1 a3760 1 .Ev PSlit d3767 3 a3769 1 .Dl PS1="${PSlit}mset${PSlit}XYZ${PSlit}mclr${PSlit}ABC" d3775 1 a3775 1 .Dq mset , d3777 1 a3777 1 .Dq mclr . d3785 1 a3785 1 .Ev PSlit d3797 2 a3798 1 .Bd -literal -offset left -compact d3802 1 d3805 3 a3807 1 and, as the SOH (Control-A) character ('\e1') will not normally affect d3971 1 a3971 1 .Ev PSlit @ 1.199 log @Use .Dv, not .Ev, to refer to LINENO, it's not an environment variable. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.198 2018/03/16 23:56:13 uwe Exp $ d3483 2 d3486 1 d3495 1 a3495 1 .Pq aka Fl o Ar monitor d3520 1 a3520 1 .Sq \&$! d3527 4 a3530 2 .Sq \&%n where n is that number. d3536 1 a3536 1 .Sq \&[ d3538 1 a3538 1 .Sq \&] d3543 1 a3543 1 .Sq \&%+ d3546 1 a3546 1 .Sq \&%% d3548 1 a3548 1 .Sq \&% d3551 1 a3551 1 .Sq \&%\- . d3561 1 a3561 1 .Dq %string d3563 1 a3563 1 .Dq string d3565 1 a3565 1 .Dq %?string d3567 1 a3567 1 .Dq string d3592 2 a3593 1 .Pq using one of the Sq \&% forms d3606 2 a3607 2 .Bd -literal -compact stop() { kill -s STOP "${@@:-%%}"; } d3624 2 a3625 2 .Bd -literal -compact PID=$(jobid -p %1) d3627 1 d3632 6 a3637 2 (%% actually refers to the sub-shell itself, but is not accessible) but the job which is the current job in the parent can be accessed as %\-. d3639 1 @ 1.198 log @Default values of PS1 and friends have only single space. Use .Li to typeset them to make that space more visible in PostScript output. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.197 2018/03/16 23:36:13 uwe Exp $ d359 1 a359 1 .Ev LINENO d364 1 a364 1 .Ev LINENO d2933 1 a2933 1 .Ev LINENO d3862 1 a3862 1 .It Ev LINENO d4061 2 a4062 2 .Ss Ev LINENO .Ev LINENO d4067 1 a4067 1 .Ev LINENO d4072 1 a4072 1 .Ev LINENO , d4075 1 a4075 1 .Ev LINENO d4079 1 a4079 1 .Ev LINENO d4082 1 a4082 1 .Ev LINENO d4087 1 a4087 1 .Ev LINENO d4090 1 a4090 1 .Ev LINENO d4093 1 a4093 1 .Ev LINENO d4096 1 a4096 1 .Ev LINENO d4099 1 a4099 1 .Ev LINENO d4103 1 a4103 1 .Ev LINENO d4114 1 a4114 1 .Ev LINENO d4118 1 a4118 1 .Ev LINENO d4121 1 a4121 1 .Ev LINENO d4145 1 a4145 1 .Ev LINENO d4153 1 a4153 1 .Ev LINENO d4155 1 a4155 1 .Dl local Fl I Ev LINENO d4157 1 a4157 1 .Ev LINENO d4162 1 a4162 1 .Ev LINENO d4164 1 a4164 1 .Dl local Oo Fl I Ns | Ns Fl N Oc Ev LINENO Ns = Ns Ar value d4166 1 a4166 1 .Ev LINENO d4171 1 a4171 1 .Dl local Fl N Ev LINENO d4173 1 a4173 1 .Ev LINENO d4178 1 a4178 1 .Ev LINENO d4182 1 a4182 1 .Ev LINENO . d4186 1 a4186 1 .Ev LINENO d4191 1 a4191 1 .Ev LINENO d4193 1 a4193 1 .Ev LINENO d4198 1 a4198 1 .Ev LINENO . d4215 1 a4215 1 .Ev LINENO @ 1.197 log @Use .Bd -literal for code example. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.196 2018/03/16 12:06:18 kre Exp $ d469 1 a469 1 .Dq $PS4 ) d3905 1 a3905 1 .Dq $ \ , d3907 1 a3907 1 .Dq # \ . d3925 1 a3925 1 .Dq > \ . d3938 1 a3938 1 .Dq + \ . @ 1.196 log @ Markup fixes (partly from uwe@@) and change some tabs to spaces, they seem to work better... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.195 2018/03/16 11:53:57 kre Exp $ d179 6 a184 12 .Bl -item -compact -offset indent .It .Li case $- in *i*) .Bl -item -compact -offset indent .It .Li # commands for interactive use only .It .Li ... .El .It .Li esac .El @ 1.195 log @ Restore some (*roff) comments deleted in previous (partially unshave the yak) for which the purpose was misunderstood. But trim one more hair. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.194 2018/03/16 11:19:24 kre Exp $ d289 1 a289 1 .Dv 0 \" $0 d293 1 a293 1 .Li ( 1 , 2 , d1008 1 a1008 1 .Li 0 , \" $0 d1596 1 a1596 1 .Dv 0 . \" $0 d1621 1 a1621 1 .It Dv @@ \" $@@ d1670 1 a1670 1 .It Dv 0 No (zero) \" $0 d1687 1 a1687 1 .Dv @@ \" $@@ d1768 1 a1768 1 .Dv @@ . \" $@@ d1842 1 a1842 1 .Dv @@ , \" $@@ d2880 2 a2881 2 .Li 1 , \" $1 .Li 2 , \" $2 d2885 2 a2886 2 .Li \&# , \" $# .Li \&* \" $* d2888 1 a2888 1 .Li \&@@ \" $@@ d3175 1 a3175 1 .Li 0 \" $0 @ 1.194 log @ Give the yak a quick trim and shave, and make one or two minor wording changes (which are, hopefully, improvements). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.193 2018/03/15 01:20:43 uwe Exp $ d289 1 a289 1 .Dv 0 d1008 1 a1008 1 .Li 0 , d1596 1 a1596 1 .Dv 0 . d1621 1 a1621 1 .It Dv @@ d1627 1 a1627 1 .Dv @@ d1670 1 a1670 1 .It Dv 0 No (zero) d1687 1 a1687 1 .Dv @@ d1768 1 a1768 1 .Dv @@ . d1842 1 a1842 1 .Dv @@ , d2880 2 a2881 2 .Li 1 , .Li 2 , d2885 2 a2886 2 .Li \&# , .Li \&* d2888 1 a2888 1 .Li \&@@ d3175 1 a3175 1 .Li 0 @ 1.193 log @Start adding more gaudy markup. Use .Li or .Dv when referring to parameters. Use more .Ic and .Ar when defining syntax. The manual is still rather inconsistent e.g. when referring to parameters where it randomly uses both $0 and 0 or $@@ and @@ - but I'm not shaving that yak at least for now. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.192 2018/03/14 10:38:52 uwe Exp $ d289 1 a289 1 .Dv 0 \" $0 d293 1 a293 1 .Li ( $1 , $2 , d1007 4 a1010 4 (except .Li $0 , which remains unchanged) are set to the arguments of the shell function. d1019 2 a1020 1 can alter variables, or other settings, of the shell. d1596 1 a1596 1 .Dv 0 . \" $0 d1687 1 a1687 1 .Dv @@ \" $@@ d1768 1 a1768 1 .Dv @@ . \" $@@ d2879 3 a2881 3 Note that the parameters .Li $1 , .Li $2 , d2884 3 d2888 1 a2888 4 .Li $# , .Li $* and .Li $@@ d2898 1 a2898 1 The only other special parameter that can be made local is @ 1.192 log @Compute tag width for the list of options in Argument List Processing, mandoc *is* up to that. Remove the part of the comment before the list that was wondering about that. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.191 2018/03/14 10:30:40 uwe Exp $ d199 6 a204 2 This also becomes $0 and the remaining arguments are set as the positional parameters of the shell ($1, $2, etc). d212 3 a214 1 those arguments become $0, $1, ... d219 9 a227 3 those arguments become $1, $2, ... If $0 has not been set by the preceding processing, it will be set to argv[0] as passed to the shell, which will d288 3 a290 1 Special parameter 0 will be set from the d292 3 a294 1 operand if given, and the positional parameters ($1, $2, etc.) d300 1 a300 1 .Dq \&+ . d596 1 a596 1 .Pq $ , d598 1 a598 1 .Pq ` , d600 1 a600 1 .Pq \e . d606 4 a609 1 .Ss Dollar Single Quotes (\&$'...') d622 1 a622 1 .Pq \&$ d625 1 a625 1 .Pq \e , d636 1 a636 1 .Dl \e \&' \&" d638 1 a638 1 .Dq \e\e d640 1 a640 1 .Dq \e' d643 1 a643 1 .Dq \e" d681 1 a681 1 .Pq \e d709 3 a711 1 One way to achieve this is to end the $'...' string immediately d724 1 a724 1 .Sq \eu d726 1 a726 1 .Sq \eU . d752 1 a752 1 .Sq \ec? d755 1 a755 1 .Sq \ec d761 1 a761 1 .Sq \ec? d766 1 a766 1 .Sq \e d769 1 a769 1 .Dq \ec\e\e . d771 1 a771 1 .Dq \ec\eX d773 1 a773 1 .Sq X d775 1 a775 1 .Sq \e d783 7 a789 4 (a NUL character) that character, and all that follow in the same $'...' string, are omitted from the resulting word. .Pp After the $'...' string has had any included escape sequences d791 2 d794 1 d807 2 d810 1 d834 1 d836 1 d845 2 d848 1 d854 1 a854 1 .Dq name=value d867 1 a867 1 .Dq name=value d873 2 d876 1 d883 1 a883 1 .Dl [n] Ns Va redir-op Ar file d890 1 a890 1 .Bq n d892 1 a892 1 .Sq 3 d894 1 a894 1 .Sq Bq 3 ) , d970 1 a970 1 .Sq \&" d972 1 a972 1 .Sq \&\e , d984 5 a988 1 an unquoted \e are joined to the following line, the \e and following d995 2 d998 1 d1007 3 a1009 1 (except $0, which remains unchanged) are set to the arguments of the shell d1030 5 a1034 1 not begin with the "magic number" whose ASCII representation is "#!", so d1047 4 a1050 1 number as a "shell procedure". d1052 1 d1117 2 d1120 1 d1123 1 a1123 1 .Sq \&| , d1125 1 a1125 1 .Dq \&! d1128 1 a1128 1 .Sq \&| d1132 1 a1132 1 .Dq \&! d1147 1 a1147 1 .Dl [!] command1 [ \&| command2 ...] d1176 3 a1178 1 If the reserved word ! precedes the pipeline, the exit status d1182 3 a1184 1 If there is no ! reserved word, the pipeline status becomes the exit status. d1201 3 a1203 1 A ; or d1209 3 a1211 1 An & terminator causes asynchronous (background) execution d1219 4 a1222 1 .Ss Background Commands \(em & d1224 3 a1226 1 is terminated by the control operator ampersand (&), the d1232 1 a1232 1 .Dl command1 & [command2 & ...] d1239 1 a1239 1 .Dq \&! d1243 2 d1246 1 d1262 1 a1262 1 .Sq \&; d1266 2 d1269 2 a1270 1 .Dq && d1272 1 a1272 1 .Dq || d1275 1 a1275 1 .Dq && d1278 1 a1278 1 .Dq || d1283 1 a1283 1 .Dq && d1285 1 a1285 1 .Dq || d1293 4 a1296 1 .Ss Flow-Control Constructs \(em if, while, until, for, case d1302 6 a1307 6 if list then list [ elif list then list ] ... [ else list ] fi d1309 1 d1328 3 a1330 3 while list do list done d1347 3 a1349 3 for variable [ in word ... ] do list done d1352 3 a1354 1 The words are expanded, or "$@@" if d1378 2 a1379 2 break [ num ] continue [ num ] d1392 1 a1392 1 .Ar num\-1 d1408 5 a1412 5 case word in [(] pattern ) [ list ] ;& [(] pattern ) [ list ] ;; \&... esac d1421 4 a1424 1 Word is expanded and matched against each pattern in turn, d1428 1 a1428 1 .Dq list , d1432 1 a1432 1 .Dq \&;& d1436 1 a1436 1 .Dq \&;; d1444 2 d1447 1 d1449 1 a1449 1 .Dl (list) d1451 1 a1451 1 .Dl { list; } d1461 3 a1463 1 Built-in commands grouped into a (list) will not affect the current shell. d1473 1 a1473 1 .Dq } d1475 1 a1475 1 .Dq \&; ) d1477 2 d1480 1 d1483 1 a1483 1 .Dl name ( ) command [ redirect... ] d1497 1 a1497 1 .Dl l() ls "$@@" d1570 1 a1570 1 .Dl name=value d1573 1 a1573 1 alphabetics, numerics, and underscores - the first of which must not be d1588 3 a1590 1 the form ${n} must be used. d1595 1 a1595 1 .Dq 0 . d1597 1 a1597 1 .Dq $10 d1599 3 a1601 1 .Dq ${1}0 . d1603 1 d1608 1 a1608 1 .It * d1620 1 a1620 1 .It @@ d1625 3 a1627 2 expansion of @@ generates zero arguments, even when @@ is double-quoted. d1629 3 a1631 1 if $1 is d1633 4 a1636 2 and $2 is .Dq def ghi , d1638 1 a1638 1 .Qq $@@ d1645 1 a1645 1 .It # d1647 1 a1647 1 .It \&? d1649 1 a1649 1 .It \- (Hyphen, or minus.) d1654 1 a1654 1 .It $ d1656 4 a1659 2 A sub-shell retains the same value of $ as its parent. .It \&! d1664 1 a1664 1 .Dq \&! d1667 1 a1667 1 .Dq \&! d1669 1 a1669 1 .It 0 (Zero.) d1672 2 d1675 1 d1685 3 a1687 2 rule is the expansion of the special parameter @@ within double quotes, as was described above. d1721 1 a1721 1 .Va HOME d1767 1 a1767 1 .Dv @@ . d1909 1 d1914 1 a1914 1 .Dl $(command) d1922 1 a1922 1 .Dl `command` d1938 2 d1941 1 d1946 1 a1946 1 .Dl $((expression)) d2020 2 d2023 1 d2028 1 a2028 1 .Dq $@@ @ 1.191 log @Small markup tweaks in Argument List Processing @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.190 2018/03/14 09:46:45 uwe Exp $ d260 2 a261 5 .\" (in italics) in a variable width font. Probably should test the actual .\" widths and use the wider, but I am not sure if mandoc is up to that... .\" (and I don't know how to get at the font that will be used easily anyway!) .\" The X's just provide a little extra space. .Bl -tag -width \-WXXlocal_linenoXX -offset indent @ 1.190 log @Instead of .Oo/.Oc use .Op directly where possible. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.189 2018/03/14 09:42:37 uwe Exp $ d223 2 d226 1 d234 2 a235 2 The set .Fl o d248 1 a248 1 .Dq - d250 1 a250 1 .Dq + @ 1.189 log @Revert previous. Fix the real problem properly. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.188 2018/03/14 07:53:14 wiz Exp $ d53 1 a53 1 .Op Ar command_file Oo Ar argument ... Oc d68 1 a68 1 .Op Ar command_name Oo Ar argument ... Oc d2056 1 a2056 1 .It Ic \&: Oo Ar arg ... Oc d2242 1 a2242 1 .It Ic export Fl p Oo Fl x Oc d3167 1 a3167 1 .It Ic ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl btfdscmlrpnv Oo Ar value Oc Oc @ 1.188 log @Remove Ic macro without effect. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.187 2018/03/13 23:03:21 uwe Exp $ d2056 1 a2056 1 .It : Oo Ar arg ... Oc @ 1.187 log @Try to improve markup in the Built-ins section. Mostly sprinkle missing .Ic and .Ar @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.186 2018/03/13 21:49:15 uwe Exp $ d2056 1 a2056 1 .It Ic : Oo Ar arg ... Oc @ 1.186 log @Try to improve markup in the Parameter Expansion section. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.185 2018/03/13 21:04:57 uwe Exp $ d2041 2 d2044 1 d2056 1 a2056 1 .It : [ Ar arg ... ] d2059 1 a2059 1 .It \&. file d2068 3 a2070 4 The return command (see .Sx Built-ins below) d2078 1 a2078 1 .It alias Op Ar name Ns Op Ar "=string ..." d2080 1 a2080 1 .Ar name=string d2095 1 a2095 1 .It bg [ Ar job ] ... d2098 1 a2098 1 .It command Oo Fl p Oc Oo Fl v Oc Oo Fl V Oc Ar command Oo Ar arg ... Oc d2120 1 a2120 1 .It cd Oo Fl P Oc Op Ar directory Op Ar replace d2133 1 a2133 1 .Sq - , d2178 1 a2178 1 .Ic cdprint d2187 1 a2187 1 .It eval Ar string ... d2190 4 a2193 2 .It exec Op Ar command arg ... Unless command is omitted, the shell process is replaced with the d2202 1 a2202 1 .Ic posix d2219 1 a2219 1 .Ic posix d2235 1 a2235 1 .It exit Op Ar exitstatus d2241 2 a2242 2 .It export Oo Fl npx Oc Ar name ... .It export Fl p Oo Fl x Oc d2250 3 a2252 1 Variables can also be un-exported using the unset built in command. d2268 4 a2271 2 still passes the value (FOO=some_value) to .Ic my_command d2299 3 a2301 3 .It fc Oo Fl e Ar editor Oc Oo Ar first Oo Ar last Oc Oc .It fc Fl l Oo Fl nr Oc Oo Ar first Oo Ar last Oc Oc .It fc Fl s Oo Ar old=new Oc Oo Ar first Oc d2307 7 a2313 3 .It Fl e No editor Use the editor named by editor to edit the commands. The editor string is a command name, subject to search via the d2338 2 a2339 1 Suppress command numbers when listing with -l. d2349 2 a2350 2 .It first .It last d2356 5 a2360 1 The value of first or last or both are one of the following: d2372 1 a2372 1 .It string d2375 3 a2377 1 If the old=new operand is not also specified with d2382 2 a2383 1 The following environment variables affect the execution of fc: d2390 1 a2390 1 .It fg Op Ar job d2394 2 a2395 2 .It fdflags Oo Fl v Oc Oo fd ... Oc .It fdflags Oo Fl v Oc Fl s Ar flags fd Oo ... Oc d2430 1 a2430 1 .It getopts Ar optstring var d2434 1 a2434 2 .Em Bell Labs -derived d2456 1 a2456 1 .Va var d2467 1 a2467 1 .Va optstring , d2472 1 a2472 1 .Va optstring d2480 1 a2480 1 .Va var d2482 1 a2482 1 .Dq \&? ; d2488 1 a2488 1 .Va optstring d2495 1 a2495 1 .Va var d2497 1 a2497 1 .Dq -- , d2499 1 a2499 1 .Va var d2501 1 a2501 1 .Dq \&? . d2505 1 a2505 1 .Op a d2507 1 a2507 1 .Op b , d2509 1 a2509 1 .Op c , d2530 1 a2530 1 .It hash Fl rv Ar command ... d2553 1 a2553 1 .It inputrc Ar file d2555 1 a2555 1 .Va file d2558 1 a2558 1 .It jobid Oo Fl g Ns \&| Ns Fl j Ns \&| Ns Fl p Oc Op Ar job d2566 1 a2566 1 .Sq \&% d2569 1 a2569 1 .Dq \&$! d2577 2 a2578 4 .Bl -dash -compact .It With .Fl g d2582 1 a2582 3 .It With .Fl j d2584 5 a2588 5 .Sq \&%n notation, where n is a number) is printed. .It With .Fl p d2591 1 d2603 4 a2606 2 .It jobs Oo Fl l Ns \&| Ns Fl p Oc Op job... Without job arguments, d2609 3 a2611 1 With job arguments, the listed jobs are shown instead. d2644 1 a2644 1 .It local Oo Fl INx Oc Oo Ar variable | \- Oc ... d2713 1 d2715 1 d2717 1 d2719 3 a2721 1 After arranging to preserve the old value and attributes, of X d2725 1 a2725 1 .Ev X , d2731 17 a2747 4 The shell uses dynamic scoping, so that if you make the variable x local to function f, which then calls function g, references to the variable x made inside g will refer to the variable x declared inside f, not to the global variable named x. d2761 4 a2764 1 Note that the parameters $1, $2, ... (see d2766 6 a2771 1 and $#, $* and $@@ (see d2775 3 a2777 1 Note that $0 however retains the value it had outside the function, d2781 1 a2781 1 .Dq \- . d2783 1 a2783 1 .Dq \- d2790 1 a2790 1 .Dq \- d2793 1 a2793 1 .Ic xtrace d2815 1 a2815 1 .Dq local \&\- d2823 1 a2823 1 .It pwd Op Fl \&LP d2863 4 a2866 2 .It read Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Oo Ar ... Oc The prompt is printed if the d2893 2 a2894 2 .It readonly Ar name ... .It readonly Oo Fl p Oc d2902 3 a2904 2 With no arguments the readonly command lists the names of all read only variables. d2908 1 a2908 1 .It return Op Ar n d2917 1 a2917 1 .Sq return d2921 3 a2923 1 Use the exit command instead, if you want to return from a script or exit d2925 1 a2925 1 .It set Oo { Fl options | Cm +options | Cm \-- } Oc Ar arg ... d2933 1 a2933 1 .Sq Fl o d2935 1 a2935 1 .Sq Cm +o d2968 3 a2970 1 The fourth use of the set command is to set the values of the shell's d2975 5 a2979 2 as the first argument to set. If no following arguments are present, the set command d2981 1 a2981 1 .Dq shift $# . ) d2983 2 a2984 2 .Dq \&$1 , .Dq \&$2 , d2987 1 a2987 1 .Dq \&$# d2989 5 a2993 2 .It setvar Ar variable Ar value Assigns value to variable. d2995 2 a2996 1 variable=value rather than using d3002 7 a3008 3 .It shift Op Ar n Shift the positional parameters n times. If n is omitted, 1 is assumed. d3012 1 a3012 1 .Va $1 d3014 1 a3014 1 .Va $2 , d3016 1 a3016 1 .Va $2 d3018 1 a3018 1 .Va $3 , d3021 1 a3021 1 .Va $# d3025 1 a3025 1 .Dq $# ) d3027 1 a3027 1 .It times d3045 5 a3049 5 .It trap Ar action signal ... .It trap \- .It trap Oo Fl l Oc .It trap Oo Fl p Oc signal ... .It trap Ar N signal ... d3058 2 a3059 1 or its equivalent, EXIT, d3068 1 a3068 1 .Sq - d3078 1 a3078 1 .Sq - d3081 1 a3081 1 .Sq - , d3156 5 a3160 4 .Dq eval . .It type Op Ar name ... Interpret each name as a command and print the resolution of the command search. d3167 1 a3167 1 .It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl btfdscmlrpnv Oo Ar value Oc Oc d3233 1 a3233 1 .It umask Oo Fl S Oc Op Ar mask d3241 1 a3241 1 .It unalias Oo Fl a Oc Oo Ar name Oc d3248 1 a3248 1 .It unset Oo Fl efvx Oc Ar name ... d3288 1 a3288 1 .It wait Oo Fl n Oc Oo Fl p Ar var Oc Op Ar job ... d3363 2 a3364 2 .Bd -literal -compact wait 100 100 100 d3367 2 a3368 2 .Bd -literal -compact wait 100 @ 1.185 log @Try to improve markup of the redirections definitions. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.184 2018/03/13 20:48:00 uwe Exp $ d1618 2 d1621 1 d1624 1 a1624 1 .Dl ${expression} d1626 4 a1629 2 where expression consists of all characters until the matching .Dq } . d1631 1 a1631 1 .Dq } d1635 1 a1635 1 .Dq } . d1639 1 a1639 1 .Dl ${parameter} d1641 3 a1643 1 The value, if any, of parameter is substituted. d1653 1 a1653 1 Pathname expansion is not performed on the results of the expansion. d1655 3 a1657 2 Field splitting is not performed on the results of the expansion, with the exception of the special rules for @@. d1663 1 a1663 1 .Dq Dv \&: d1667 20 a1686 9 .It ${parameter:\(miword} Use Default Values. If parameter is unset or null, the expansion of word is substituted; otherwise, the value of parameter is substituted. .It ${parameter:=word} Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. In all cases, the final value of parameter is substituted. d1689 9 a1697 4 .It ${parameter:?[word]} Indicate Error if Null or Unset. If parameter is unset or null, the expansion of word (or a message indicating it is unset if word is omitted) d1702 19 a1720 9 If the parameter is set, its value is substituted. .It ${parameter:+word} Use Alternative Value. If parameter is unset or null, null is substituted; otherwise, the expansion of word is substituted. The value of parameter is not used in this expansion. .It ${#parameter} String Length. The length in characters of the value of parameter. d1728 5 a1732 1 If parameter is * or @@, the result of the expansion is unspecified. d1737 8 a1744 4 .It ${parameter%word} Remove Smallest Suffix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the d1746 4 a1749 2 If the word is to start with a .Sq \&% d1751 8 a1758 4 .It ${parameter%%word} Remove Largest Suffix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the largest d1761 1 a1761 1 .Dq %% d1763 1 a1763 1 .Dq \&% d1765 9 a1773 5 .Sq \&* . .It ${parameter#word} Remove Smallest Prefix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the d1775 4 a1778 2 If the word is to start with a .Sq \&# d1780 8 a1787 4 .It ${parameter##word} Remove Largest Prefix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the largest d1790 1 a1790 1 .Sq \&# d1792 1 a1792 1 .Dq %% d1794 1 a1794 1 .Dq \&% . d1796 2 @ 1.184 log @Fix horrendous markup abuse in the here-document example. Consistently spell "here-document" in full. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.183 2018/03/13 20:40:52 uwe Exp $ d862 4 a865 2 .It Oo Ar n Oc Ns > Ar file Redirect standard output (or n) to d867 1 a867 1 .It Oo Ar n Oc Ns >| file d871 4 a874 2 .It Oo Ar n Oc Ns >> Ar file Append standard output (or n) to d876 1 a876 1 .It Oo Ar n Oc Ns < Ar file d881 1 a881 1 .It Oo Ar n1 Oc Ns <& Ns Ar n2 d888 1 a888 1 .It Oo Ar n Oc Ns <&- d891 1 a891 1 .It Oo Ar n1 Oc Ns >& Ns Ar n2 d896 4 a899 3 .It Oo Ar n Oc Ns >&- Close standard output (or n). .It Oo Ar n Oc Ns <> Ar file d908 4 a911 4 .Bd -literal -offset indent [n]<< delimiter \&... here-doc-text ... delimiter d940 1 a940 1 .Dq <<\(mi d942 1 a942 1 .Dq << , @ 1.183 log @Spell "here-document" with a hyphen, don't mark it up as a command. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.182 2018/03/13 20:39:25 uwe Exp $ d903 5 a907 6 .Bl -item -offset indent .It .Li [n]<< delimiter .Dl here-doc-text ... .Li delimiter .El d912 1 a912 1 the here-doc redirection operator. d915 1 a915 1 first, and subsequent here-doc-text for later here-doc redirections d942 2 a943 1 newline are simply removed while reading the here-doc, which thus guarantees @ 1.182 log @Mark up "in" (of the "for" command) appropriately. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.181 2018/03/13 20:29:13 uwe Exp $ d1434 1 a1434 2 which reads and processes the .Ic here document @ 1.181 log @Use \(or not \*(Ba when discussing case patterns. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.180 2018/03/13 20:18:16 uwe Exp $ d1267 1 a1267 1 .Dq in d1272 1 a1272 1 .Dq in @ 1.180 log @Use \(em for em-dash @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.179 2018/03/13 20:08:11 uwe Exp $ d1330 1 a1330 1 .Dq \*(Ba @ 1.179 log @Standalone | means \[ba] while we want \[or] so add \& protection to the few places where it was missing. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.178 2018/03/13 19:43:52 uwe Exp $ d950 1 a950 1 normal programs -- and the command is searched for (by name) in that order. d1130 1 a1130 1 it executes in the current shell -- but any effect it has on the d1148 1 a1148 1 .Ss Background Commands -- & d1151 1 a1151 1 shell executes the command asynchronously -- that is, the shell does not d1167 1 a1167 1 .Ss Lists -- Generally Speaking d1211 1 a1211 1 .Ss Flow-Control Constructs -- if, while, until, for, case @ 1.178 log @.Dl is a a single line .Bd -literal -offset indent so don't abuse multiple consecutive .Dl and use proper .Bd instead. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.177 2018/03/13 19:35:46 uwe Exp $ d553 1 a553 1 .Dl & && \&( \&) \&; ;; ;& | || d1084 1 a1084 1 .Dl [!] command1 [ | command2 ...] d1123 1 a1123 1 .Dl $ command1 2>&1 | command2 @ 1.177 log @.Bd expects the display type to come first, so move -compact to the end. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.176 2018/03/13 19:18:53 uwe Exp $ d1413 6 a1418 3 .Dl hello() cat < d580 1 a580 1 .Pq Li \&$ , d582 1 a582 1 .Pq Li \&` , d584 1 a584 1 .Pq Li \e . d590 1 a590 4 .\" .\" .Ss Dollar Single Quotes ( Li \&$'...' ) .\" d603 1 a603 1 .Pq Li \&$ d606 1 a606 1 .Pq Li \e , d617 1 a617 1 .Dl \e \&' \(dq d619 1 a619 1 .Dq Li \e\e d621 1 a621 1 .Dq Li \e' d624 1 a624 1 .Dq Li \e\(dq d662 1 a662 1 .Pq Li \e d690 1 a690 3 One way to achieve this is to end the .Li $'...' string immediately d703 1 a703 1 .Sq Li \eu d705 1 a705 1 .Sq Li \eU . d731 1 a731 1 .Sq Li \ec? d734 1 a734 1 .Sq Li \ec d740 1 a740 1 .Sq Li \ec? d745 1 a745 1 .Sq Li \e d748 1 a748 1 .Dq Li \ec\e\e . d750 1 a750 1 .Dq Li \ec\e Ns Ar X\^ d752 1 a752 1 .Sq Ar X\^ d754 1 a754 1 .Sq Li \e d762 4 a765 7 (a NUL character) that character, and all that follow in the same .Li $'...' string, are omitted from the resulting word. .Pp After the .Li $'...' string has had any included escape sequences a766 2 .\" .\" a767 1 .\" a779 2 .\" .\" a780 1 .\" a803 1 .\" a804 1 .\" a812 2 .\" .\" a813 1 .\" d819 1 a819 1 .Dq Ar name Ns Li = Ns Ar value d832 1 a832 1 .Dq Ar name Ns Li = Ns Ar value a837 2 .\" .\" a838 1 .\" d845 1 a845 1 .Dl Oo Ar n Oc Ns Va redir-op Ar file d852 1 a852 1 .Op Ar n d854 1 a854 1 .Sq Li 3 d856 1 a856 1 .Li [3] ) , d862 2 a863 4 .It Oo Ar n Oc Ns Ic > Ar file Redirect standard output (or .Ar n ) to d865 1 a865 1 .It Oo Ar n Oc Ns Ic >| Ar file d869 2 a870 4 .It Oo Ar n Oc Ns Ic >> Ar file Append standard output (or .Ar n ) to d872 1 a872 1 .It Oo Ar n Oc Ns Ic < Ar file d877 1 a877 1 .It Oo Ar n1 Oc Ns Ic <& Ns Ar n2 d884 1 a884 1 .It Oo Ar n Oc Ns Ic <&- d887 1 a887 1 .It Oo Ar n1 Oc Ns Ic >& Ns Ar n2 d892 3 a894 4 .It Oo Ar n Oc Ns Ic >&- Close standard output (or .Ar n ) . .It Oo Ar n Oc Ns Ic <> Ar file d903 6 a908 5 .Bd -unfilled -offset indent .Oo Ar n Oc Ns Ic << Ar delimiter .Li \&... here-doc-text ... .Ar delimiter .Ed d913 1 a913 1 the here-document redirection operator. d916 1 a916 1 first, and subsequent here-doc-text for later here-document redirections d928 1 a928 1 .Sq Li \(dq d930 1 a930 1 .Sq Li \&\e , d936 1 a936 1 .Ic <<- d938 1 a938 1 .Ic << , d942 2 a943 7 an unquoted .Li \e are joined to the following line, the .Li \e and following newline are simply removed while reading the here-document, which thus guarantees a947 2 .\" .\" a948 1 .\" d950 1 a950 1 normal programs \(em and the command is searched for (by name) in that order. d957 1 a957 3 (except .Li $0 , which remains unchanged) are set to the arguments of the shell d978 1 a978 5 not begin with the .Dq magic number whose ASCII representation is .Dq Li "#!" , so d991 1 a991 4 number as a .Dq shell procedure . .\" .\" a992 1 .\" a1056 2 .\" .\" a1057 1 .\" d1060 1 a1060 1 .Sq Ic \(ba , d1062 1 a1062 1 .Dq Ic \&! d1065 1 a1065 1 .Sq Ic \(ba d1069 1 a1069 1 .Dq Ic \&! d1084 1 a1084 1 .Dl [!] command1 Op Li \&| command2 No ... d1113 1 a1113 3 If the reserved word .Dq Ic \&! precedes the pipeline, the exit status d1117 1 a1117 3 If there is no .Dq Ic \&! reserved word, the pipeline status becomes the exit status. d1123 1 a1123 1 .Dl $ command1 2>&1 \&| command2 d1130 1 a1130 1 it executes in the current shell \(em but any effect it has on the d1134 1 a1134 3 A .Li \&; or d1140 1 a1140 3 An .Li \&& terminator causes asynchronous (background) execution d1148 1 a1148 4 .\" .\" .Ss Background Commands \(em Ic \&& .\" d1150 2 a1151 4 is terminated by the control operator ampersand .Pq Li \&& , the shell executes the command asynchronously \(em that is, the shell does not d1156 1 a1156 1 .Dl command1 & Op Li command2 & No ... d1163 1 a1163 1 .Dq Dv \&! \" $! d1167 1 a1167 4 .\" .\" .Ss Lists \(em Generally Speaking .\" d1183 1 a1183 1 .Sq Li \&; a1186 2 .\" .\" d1188 1 a1188 2 .\" .Dq Li \&&& d1190 1 a1190 1 .Dq Li \&|| d1193 1 a1193 1 .Dq Li \&&& d1196 1 a1196 1 .Dq Li \&|| d1201 1 a1201 1 .Dq Li \&&& d1203 1 a1203 1 .Dq Li \&|| d1211 1 a1211 4 .\" .\" .Ss Flow-Control Constructs \(em Ic if , while , until , for , case .\" d1217 6 a1222 6 .Ic if Ar list .Ic then Ar list .Ic [ elif Ar list .Ic then Ar list ] No ... .Ic [ else Ar list ] .Ic fi a1223 1 .Pp d1242 3 a1244 3 .Ic while Ar list .Ic do Ar list .Ic done d1261 3 a1263 3 .Ic for Ar variable Op Ic in Ar word No ... .Ic do Ar list .Ic done d1266 2 a1267 4 The words are expanded, or .Li \*q$@@\*q if .Ic in d1272 1 a1272 1 .Ic in d1290 2 a1291 2 .Ic break Op Ar num .Ic continue Op Ar num d1304 1 a1304 1 .Ar num\^ Ns -1 d1320 5 a1324 5 .Ic case Ar word Ic in .Oo Ic \&( Oc Ar pattern Ns Ic \&) Oo Ar list Oc Ic \&;& .Oo Ic \&( Oc Ar pattern Ns Ic \&) Oo Ar list Oc Ic \&;; .No \&... .Ic esac d1330 1 a1330 1 .Dq \(or d1333 1 a1333 4 .Ar word is expanded and matched against each .Ar pattern in turn, d1337 1 a1337 1 .Ar list , d1341 1 a1341 1 .Dq Ic \&;& d1345 1 a1345 1 .Dq Ic \&;; a1352 2 .\" .\" a1353 1 .\" d1355 1 a1355 1 .Dl Ic \&( Ns Ar list Ns Ic \&) d1357 1 a1357 1 .Dl Ic \&{ Ar list Ns Ic \&; \&} d1367 1 a1367 3 Built-in commands grouped into a .Li \&( Ns Ar list Ns \&) will not affect the current shell. d1377 1 a1377 1 .Dq Ic } d1379 1 a1379 1 .Dq Ic \&; ) a1380 2 .\" .\" a1381 1 .\" d1384 1 a1384 1 .Dl Ar name Ns Ic \&() Ar command Op Ar redirect No ... d1398 1 a1398 1 .Dl l() ls \*q$@@\*q d1413 3 a1415 6 .Bd -literal -offset indent hello() cat < " . d3943 1 a3943 1 .Dq Li "+ " . d3961 1 a3961 1 .Dv PSlit d4066 2 a4067 2 .Ss Dv LINENO .Dv LINENO d4072 1 a4072 1 .Dv LINENO d4077 1 a4077 1 .Dv LINENO , d4080 1 a4080 1 .Dv LINENO d4084 1 a4084 1 .Dv LINENO d4087 1 a4087 1 .Dv LINENO d4092 1 a4092 1 .Dv LINENO d4095 1 a4095 1 .Dv LINENO d4098 1 a4098 1 .Dv LINENO d4101 1 a4101 1 .Dv LINENO d4104 1 a4104 1 .Dv LINENO d4108 1 a4108 1 .Dv LINENO d4119 1 a4119 1 .Dv LINENO d4123 1 a4123 1 .Dv LINENO d4126 1 a4126 1 .Dv LINENO d4150 1 a4150 1 .Dv LINENO d4158 1 a4158 1 .Dv LINENO d4160 1 a4160 1 .Dl local Fl I Dv LINENO d4162 1 a4162 1 .Dv LINENO d4167 1 a4167 1 .Dv LINENO d4169 1 a4169 1 .Dl local Oo Fl I Ns | Ns Fl N Oc Dv LINENO Ns = Ns Ar value d4171 1 a4171 1 .Dv LINENO d4176 1 a4176 1 .Dl local Fl N Dv LINENO d4178 1 a4178 1 .Dv LINENO d4183 1 a4183 1 .Dv LINENO d4187 1 a4187 1 .Dv LINENO . d4191 1 a4191 1 .Dv LINENO d4196 1 a4196 1 .Dv LINENO d4198 1 a4198 1 .Dv LINENO d4203 1 a4203 1 .Dv LINENO . d4220 1 a4220 1 .Dv LINENO @ 1.175.2.3 log @Sync with HEAD @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.206 2018/05/03 05:11:43 wiz Exp $ d34 1 a34 1 .Dd May 3, 2018 d178 1 d2324 1 a2324 1 unless the descriptors refer to the standard input, d2330 3 d3286 1 d3303 1 @ 1.175.2.4 log @Sync with HEAD Resolve a couple of conflicts (result of the uimin/uimax changes) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.208 2018/09/04 23:16:30 kre Exp $ d491 1 a491 2 If set when a pipeline is created, the way the exit status of the pipeline is determined d1158 5 a1162 5 option was set when a pipeline was started, the pipeline status is the status of the last (lexically last, i.e.: rightmost) command in the pipeline to exit with non-zero exit status, or zero, if, and only if, all commands in the pipeline exited with a status of zero. d1165 1 a1165 1 option was not set, which is the default state, d1167 1 a1167 1 status of the last (rightmost) command in the pipeline, d1906 1 a1906 2 Command substitution occurs when a word contains a command list enclosed as follows: d1908 1 a1908 1 .Dl Ic $( Ns Ar list Ns Ic \&) d1910 11 a1920 17 or the older .Pq Dq backquoted version, which is best avoided: .Pp .Dl Ic \&` Ns Ar list Ns Ns Ic \&` .Pp See the section .Sx Complex Commands above for the definition of .Ic list . .Pp The shell expands the command substitution by executing the .Ar list in a sub-shell environment and replacing the command substitution with the standard output of the .Ar list after removing any sequence of one or more d1922 1 a1922 1 from the end of the substitution. d1927 2 a1928 2 they may be used to separate fields .Pq "as spaces usually are" a1931 85 .Pp Note that if a command substitution includes commands to be run in the background, the sub-shell running those commands will only wait for them to complete if an appropriate .Ic wait command is included in the command list. However, the shell in which the result of the command substitution will be used will wait for both the sub-shell to exit and for the file descriptor that was initially standard output for the command substitution sub-shell to be closed. In some circumstances this might not happen until all processes started by the command substitution have finished. .\" While the exit of the sub-shell closes its standard output, .\" any background process left running may still .\" have that file descriptor open. .\" This includes yet another sub-shell which might have been .\" (almost invisibly) created to wait for some other command to complete, .\" and even where the background command has had its .\" standard output redirected or closed, .\" the waiting sub-shell may still have it open. .\" Thus there is no guarantee that the result of a command substitution .\" will be available in the shell which is to use it before all of .\" the commands started by the command substitution have completed, .\" though careful coding can often avoid delays beyond the termination .\" of the command substitution sub-shell. .\" .Pp .\" For example, assuming a script were to contain the following .\" code (which could be done better other ways, attempting .\" this kind of trickery is not recommended): .\" .Bd -literal -offset indent .\" if [ "$( printf "Ready? " >&2; read ans; printf "${ans}"; .\" { sleep 120 >/dev/null && kill $$ >/dev/null 2>&1; }& )" = go ] .\" then .\" printf Working... .\" # more code .\" fi .\" .Ed .\" .Pp .\" the .\" .Dq Working... .\" output will not be printed, and code that follows will never be executed. .\" Nor will anything later in the script .\" .Po .\" unless .\" .Dv SIGTERM .\" is trapped or ignored .\" .Pc . .\" .Pp .\" The intent is to prompt the user, wait for the user to .\" answer, then if the answer was .\" .Dq go .\" do the appropriate work, but set a 2 minute time limit .\" on completing that work. .\" If the work is not done by then, kill the shell doing it. .\" .Pp .\" It will usually not work as written, as while the 2 minute .\" .Sq sleep .\" has its standard output redirected, as does the .\" .Sq kill .\" that follows (which also redirects standard error, .\" so the user would not see an error if the work were .\" completed and there was no parent process left to kill); .\" the sub-shell waiting for the .\" .Sq sleep .\" to finish successfully, so it can start the .\" .Sq kill , .\" does not. .\" It waits, with standard output still open, .\" for the 2 minutes until the sleep is done, .\" even though the kill is not going to need that file descriptor, .\" and there is nothing else which could. .\" The command substitution does not complete until after .\" the kill has executed and the background sub-shell .\" finishes \(en at which time the shell running it is .\" presumably dead. .\" .Pp .\" Rewriting the background sub-shell part of that as .\" .Dl "{ sleep 120 && kill $$ 2>&1; } >/dev/null &" .\" would allow this .\" .Nm .\" to perform as expected, but that is not guaranteed, .\" not all shells would behave as planned. .\" It is advised to avoid starting background processes .\" from within a command substitution. @ 1.175.2.5 log @Sync with HEAD, resolve a couple of conflicts @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.209 2018/11/23 20:40:06 kre Exp $ d446 1 a446 1 .It Fl X Em xlock @ 1.175.2.6 log @Sync with HEAD, resolve a few conflicts @ text @d1 1 a1 1 .\" $NetBSD$ d34 1 a34 1 .Dd December 12, 2018 a135 2 in the user's home directory .Pq \&$HOME , d146 3 a148 13 the shell then performs parameter and arithmetic expansion on the value of .Ev ENV , (these are described later) and then reads commands from the file name that results. If .Ev ENV contains a command substitution, or one of the other expansions fails, or if there are no expansions to expand, the value of .Ev ENV is used as the file name. .Pp d270 1 a270 2 while this flag is set, unless the variable has been marked as not for export. a519 5 the format of the output of the .Ic kill Fl l command, where posix mode causes the names of the signals be separated by either a single space or newline, and where otherwise sufficient spaces are inserted to generate nice looking columns, d524 1 a524 1 .Dq "{\ }" d645 1 a645 2 the two characters, the backslash escape and the newline, are removed from the input string. a2262 1 .\" a2281 1 .\" a2298 1 .\" a2301 1 .\" a2323 1 .\" a2390 1 .\" a2393 1 .\" a2435 1 .\" d2442 2 a2443 4 .\" .It Ic export Oo Fl nx Oc Ar name Ns Oo =value Oc ... .It Ic export Oo Fl x Oc Oo Fl p Oo Ar name ... Oc Oc .It Ic export Fl q Oo Fl x Oc Ar name ... a2465 1 export FOO # this command will fail (non-fatally) d2476 1 a2476 1 same time it is exported (or unexported, etc) by writing d2478 1 a2478 1 .Dl export [-nx] name=value d2480 1 a2480 2 With no arguments the export command lists the names of all set exported variables, d2483 1 a2483 1 was given, all set variables marked not for export. d2486 1 a2486 6 option specified, the output will be formatted suitably for non-interactive use, and unset variables are included. When .Fl p is given, variable names, but not values, may also be given, in which case output is limited to the variables named. d2488 1 a2488 15 With .Fl q and a list of variable names, the .Ic export command will exit with status 0 if all the named variables have been marked for export, or 1 if any are not so marked. If .Fl x is also given, the test is instead for variables marked not to be exported. .Pp Other than with .Fl q , the d2491 2 a2492 1 unless an attempt is made to export a variable which has a2494 7 In all cases if an invalid option, or option combination, is given, or an invalid variable name is present, .Ic export will write a message to the standard error output, and exit with a non-zero status. A non-interactive shell will terminate. d2499 1 a2499 2 and creating it again \(en provided the variable is not also read-only. .\" a2590 1 .\" a2594 1 .\" a2630 1 .\" a2730 1 .\" a2753 1 .\" a2758 1 .\" a2803 1 .\" a2844 1 .\" a2997 15 If any of the shell's magic variables (those which return a value which may vary without the variable being explicitly altered, e.g.: .Dv SECONDS or .Dv HOSTNAME ) are made local in a function, they will lose their special properties when set within the function, including by the .Ic local command itself (if not to be set in the function, there is little point in making a variable local) but those properties will be restored when the function returns. a3023 1 .\" a3063 1 .\" d3094 3 a3096 6 .\" .It Ic readonly Ar name Ns Oo =value Oc ... .It Ic readonly Oo Fl p Oo Ar name ... Oc Oc .It Ic readonly Fl q Ar name ... With no options, the specified names are marked as read only, so that they cannot be d3105 1 a3105 1 command lists the names of all set read only variables. d3108 1 a3108 29 option specified, the output will be formatted suitably for non-interactive use, and unset variables are included. When the .Fl p option is given, a list of variable names (without values) may also be specified, in which case output is limited to the named variables. .Pp With the .Fl q option, the .Ic readonly command tests the read-only status of the variables listed and exits with status 0 if all named variables are read-only, or with status 1 if any are not read-only. .Pp Other than as specified for .Fl q the .Ic readonly command normally exits with status 0. In all cases, if an unknown option, or an invalid option combination, or an invalid variable name, is given; or a variable which was already read-only is attempted to be set; the exit status will not be zero, a diagnostic message will be written to the standard error output, and a non-interactive shell will terminate. .\" a3125 1 .\" a3189 1 .\" a3202 1 .\" a3227 1 .\" a3245 1 .\" a3309 5 These variants of the trap command may be executed in a sub-shell .Pq "such as in a command substitution" , provided they appear as the sole, or first, command in that sub-shell, in which case the state of traps from the parent of that sub-shell is reported. a3357 1 .\" a3367 1 .\" a3489 1 .\" a3931 24 .It Ev ENV Names the file sourced at startup by the shell. Unused by this shell after initialization, but is usually passed through the environment to descendant shells. .It Ev EUSER Set to the login name of the effective user id running the shell, as returned by .Bd -compact -literal -offset indent getpwuid(geteuid())->pw_name .Ed .Po See .Xr getpwuid 3 and .Xr geteuid 2 for more details. .Pc This is obtained each time .Ev EUSER is expanded, so changes to the shell's execution identity cause updates without further action. If unset, it returns nothing. If set it loses its special properties, and is simply a variable. d3950 2 a3951 1 If set it loses its special properties, and is simply a variable. a4002 16 .It Ev POSIXLY_CORRECT If set in the environment upon initialization of the shell, then the shell option .Ic posix will be set. .Po See the description of the .Ic set command in the .Sx Built-ins section. .Pc After initialization it is unused by the shell, but is usually passed through the environment to descendant processes, including other instances of the shell, which may interpret it in a similar way. d4094 1 a4095 1 If set, it loses its special properties, and becomes a normal variable. d4107 1 a4107 1 has not been set or unset. d4129 2 a4130 1 If set, it loses its special properties, and becomes a normal variable. d4374 15 @ 1.175.2.7 log @Sync with HEAD @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.175.2.6 2018/12/26 14:01:03 pgoyette Exp $ a4256 8 Should the error message .Dq "RANDOM initialisation failed" appear on standard error, it indicates that the source of good random numbers was not available, and .Ev RANDOM has instead been seeded with a more predictable value. The following sequence of random numbers will not be as unpredictable as they otherwise would be. @ 1.174 log @Implement the -X option - an apparent variant of -x which sends all trace output to the stderr which existed when the -X option was (last) enabled. It also enables tracing by enabling -x (and when reset, +X, also resets the 'x' flag (+x)). Note that it is still -x/+x which actually enables/disables the trace output. Hence "apparent variant" - what -X actually does (aside from setting -x) is just to lock the trace output, rather than having it follow wherever stderr is later redirected. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.173 2017/11/15 08:50:07 kre Exp $ d3811 10 a3820 8 can be exported, made readonly (which prevents attempts to assign to it, and to unset it, but which does not change the value, that is the current line number, from being obtained when .Ev LINENO is referenced,) and can be unset. All of those act as they would with any other variable. @ 1.173 log @ Correct a typo: s/ at / an / @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.172 2017/10/30 15:37:41 wiz Exp $ d37 1 a37 1 .ds flags abCEeFfhIiLmnpquVvx d437 20 d461 6 d2662 10 @ 1.172 log @Minor spellchecking changes. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.171 2017/10/29 00:20:42 kre Exp $ d2641 1 a2641 1 unless an undefined option is used, or at attempt is made to @ 1.171 log @ Correct a markup typo (Sv -> Dv) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.170 2017/10/28 06:36:17 kre Exp $ d643 1 a643 1 zeroes if needed. d682 1 a682 1 Leading zeroes can be used to pad the sequences to the maximum d736 1 a736 1 (a nul character) that character, and all that follow in the d2155 1 a2155 1 provided the variable is not also readonly. d2185 1 a2185 1 or un-exporting, readonly variables. d2187 1 a2187 1 and creating it again \(en provided it is not also readonly. d2854 1 a2854 1 The first output line gives the cpu and system times consumed by the d3527 1 a3527 1 builtin command, described in @ 1.170 log @Add '-n' and '-p var' args to the wait command (-n: wait for any, -p var: set var to identifier, from arg list, or PID if no job args) of the job for which status is returned (becomes $? after wait.) Note: var is unset if the status returned from wait came from wait itself rather than from some job exiting (so it is now possible to tell whether 127 means "no such job" or "job did exit(127)", and whether $? > 128 means "wait was interrupted" or "job was killed by a signal or did exit(>128)". ($? is too limited to to allow indicating whether the job died with a signal, or exited with a status such that it looks like it did...) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.169 2017/10/25 05:42:56 kre Exp $ d3304 1 a3304 1 .Sv STOP @ 1.169 log @Add options to the builtin jobid command to allow discovering the process group (-g), the process leader pid (-p) ($! if the job was &'d) and the job identifier (-j) (the %n that refers to the job) in addition to (default) the list of all pids in the job (which it has always done). No change to the (single) "job" arg, which is a specifier of the job: the process leader pid, or one of the % forms, and defaults to %% (aka %+). (This is all now documented in sh(1)) Also document the jobs command properly (no change to the command, just document what it actually is.) And while here, a whole new section in sh(1) "Job Control". It probably needs better wording, but this is (perhaps) better than the nothing that was there before. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.168 2017/10/15 12:01:43 pgoyette Exp $ d3107 45 a3151 6 .It wait Op Ar job Wait for the specified job to complete and return the exit status of the last process in the job, or 127 if the job is not a current child of the shell. If the argument is omitted, wait for all jobs to complete and then return an exit status of zero. d3153 4 a3156 1 its exit status will be greater than 128. d3164 25 @ 1.168 log @Fix typo: s/one or mode/one or more/ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.167 2017/10/06 21:09:45 kre Exp $ d34 1 a34 1 .Dd October 6, 2017 d2436 2 a2437 2 .It jobid Op Ar job Print the process id's of the processes in the job. d2441 46 a2486 2 .It jobs This command lists out all the background processes d2488 33 d3123 144 d3922 2 @ 1.167 log @Three fixes and a change to ~ expansions 1. A serious bug introduced 3 1/2 months ago (approx) (rev 1.116) which broke all but the simple cases of ~ expansions is fixed (amazingly, given the magnitude of this problem, no-one noticed!) 2. An ancient bug (probably from when ~ expansion was first addedin 1994, and certainly is in NetBSD-6 vintage shells) where ${UnSeT:-~} (and similar) does not expand the ~ is fixed (note that ${UnSeT:-~/} does expand, this should give a clue to the cause of the problem. 3. A fix/change to make the effects of ~ expansions on ${UnSeT:=whatever} identical to those in UnSeT=whatever In particular, with HOME=/foo ${UnSeT:=~:~} now assigns, and expands to, /foo:/foo rather than ~:~ just as VAR=~:~ assigns /foo:/foo to VAR. Note this is even after the previous fix (ie: appending a '/' would not change the results here.) It is hard to call this one a bug fix for certain (though I believe it is) as many other shells also produce different results for the ${V:=...} expansions than they do for V=... (though not all the same as we did). POSIX is not clear about this, expanding ~ after : in VAR=whatever assignments is clear, whether ${U:=whatever} assignments should be treated the same way is not stated, one way or the other. 4. Change to make ':' terminate the user name in a ~ expansion in all cases, not only in assignments. This makes sense, as ':' is one character that cannot occur in user names, no matter how otherwise weird they become. bash (incl in posix mode) ksh93 and bosh all act this way, whereas most other shells (and POSIX) do not. Because this is clearly an extension to POSIX, do this one only when not in posix mode (not set -o posix). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.166 2017/08/27 20:37:59 wiz Exp $ d2140 1 a2140 1 but one or mode names, @ 1.166 log @Whitespace fixes. Fix a typo. Refer to emacs using Ic, since emacs(1) does not exist in the base system. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.165 2017/08/27 20:32:20 wiz Exp $ d34 1 a34 1 .Dd August 20, 2017 d480 4 d1562 6 a1567 3 All the following characters in the word up to a slash (/) or the end of the word are treated as a user name and are replaced with the named user's home directory. d1573 5 @ 1.165 log @Remove unnecessary Tn macro. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.164 2017/08/21 13:20:49 kre Exp $ d633 1 a633 1 followed by one, two or three, octal digits d647 1 a647 1 .Po So 0 Sc Ns \&.. Ns So 9 Sc Ns , So A Sc Ns \&.. Ns So F Sc Ns , or So a Sc Ns \&.. Ns So f Sc Ns . Pc d3076 2 a3077 3 mode uses commands similar to a subset available in the .Xr emacs 1 d3190 1 a3190 1 .Xr edlitline 7 @ 1.164 log @Add support for $'...' quoting (based upon C "..." strings, with \ expansions.) Implementation largely obtained from FreeBSD, with adaptations to meet the needs and style of this sh, some updates to agree with the current POSIX spec, and a few other minor changes. The POSIX spec for this ( http://austingroupbugs.net/view.php?id=249 ) [see note 2809 for the current proposed text] is yet to be approved, so might change. It currently leaves several aspects as unspecified, this implementation handles those as: Where more than 2 hex digits follow \x this implementation processes the first two as hex, the following characters are processed as if the \x sequence was not present. The value obtained from a \nnn octal sequence is truncated to the low 8 bits (if a bigger value is written, eg: \456.) Invalid escape sequences are errors. Invalid \u (or \U) code points are errors if known to be invalid, otherwise can generate a '?' character. Where any escape sequence generates nul ('\0') that char, and the rest of the $'...' string is discarded, but anything remaining in the word is processed, ie: aaa$'bbb\0ccc'ddd produces the same as aaa'bbb'ddd. Differences from FreeBSD: FreeBSD allows only exactly 4 or 8 hex digits for \u and \U (as does C, but the current sh proposal differs.) reeBSD also continues consuming as many hex digits as exist after \x (permitted by the spec, but insane), and reject \u0000 as invalid). Some of this is possibly because that their implementation is based upon an earlier proposal, perhaps note 590 - though that has been updated several times. Differences from the current POSIX proposal: We currently always generate UTF-8 for the \u & \U escapes. We should generate the equivalent character from the current locale's character set (and UTF8 only if that is what the current locale uses.) If anyone would like to correct that, go ahead. We (and FreeBSD) generate (X & 0x1F) for \cX escapes where we should generate the appropriate control character (SOH for \cA for example) with whatever value that has in the current character set. Apart from EBCDIC, which we do not support, I've never seen a case where they differ, so ... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.163 2017/07/25 08:37:48 wiz Exp $ d89 1 a89 2 .Tn POSIX 1003.2 and 1003.2a specifications for the shell. d564 1 a564 3 and yet to be included in the .Tn POSIX standard. d610 1 a610 1 .Sq Tn BEL ) d703 1 a703 2 .Tn ASCII value of the character following the d711 2 a712 8 yields the .Tn ASCII .Tn DEL character (0x7F). Note that to obtain the .Tn ASCII .Tn FS character (0x1C) this way, d777 1 a777 3 BNF in the .Tn POSIX 1003.2 document). d948 1 a948 3 not begin with the "magic number" whose .Tn ASCII representation is "#!", so d1743 1 a1743 3 data type (this is an extension to .Tn POSIX , which requires only d2102 1 a2102 3 This behavior is required by the .Tn POSIX standard, so when the d2296 1 a2296 2 The .Tn POSIX @ 1.163 log @Remove trailing whitespace. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.162 2017/07/24 14:17:11 kre Exp $ d34 1 a34 1 .Dd July 15, 2017 d531 6 a536 2 There are three types of quoting: matched single quotes, matched double quotes, and backslash. d561 186 d827 1 a827 1 .Dl [n] Va redir-op Ar file @ 1.162 log @Implement the "pipefail" option (same semantics as in other shells) to cause (when set, which it is not by default) the exit status of a pipe to be 0 iff all commands in the pipe exited with status 0, and otherwise, the status of the rightmost command to exit with a non-0 status. In the doc, while describing this, also reword some of the text about commands in general, how they are structured, and when they are executed. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.161 2017/07/24 13:21:14 kre Exp $ d834 1 a834 1 Which is a sequence of one or more AND-OR lists. d907 1 a907 1 If the reserved word ! precedes the pipeline, the exit status @ 1.161 log @Add support for ++ and -- (pre & post) and ',' to arithmetic. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.160 2017/07/24 12:36:02 kre Exp $ d456 6 d831 16 a846 12 More generally, a command is one of the following: .Bl -bullet .It simple command .It pipeline .It list or compound-list .It compound command .It function definition d849 2 a850 2 Unless otherwise stated, the exit status of a command is that of the last simple command executed by the command. d858 11 d870 1 a870 1 the last command is connected to the standard input d873 2 a874 1 command is inherited from the shell, as usual. d882 1 a882 1 The standard input, standard output, or both of a command is d889 23 a911 7 If the reserved word ! does not precede the pipeline, the exit status is the exit status of the last command specified in the pipeline. Otherwise, the exit status is the logical NOT of the exit status of the last command. That is, if the last command returns zero, the exit status is 1; if the last command returns greater than zero, the exit status is zero. d922 6 d930 6 a935 3 terminator causes the preceding AND-OR-list (described next) to be executed sequentially; a & causes asynchronous execution of the preceding AND-OR-list. a941 5 .Pp Note that unlike some other shells, each process in the pipeline is a child of the invoking shell (unless it is a shell built-in, in which case it executes in the current shell -- but any effect it has on the environment is wiped). d943 2 a944 1 If a command is terminated by the control operator ampersand (&), the d959 2 a960 1 .Sx Special Parameters ) . d965 7 d981 1 a981 1 .Ss Short-Circuit List Operators d986 1 d988 2 a989 2 executes the first command, and then executes the second command if and only if the exit status of the first command is zero. d991 4 a994 2 is similar, but executes the second command if and only if the exit status of the first command is nonzero. d1000 1 a1000 1 .Dq true || echo bar && echo baz d1005 2 a1006 1 .Ss Flow-Control Constructs -- if, while, for, case d1060 3 a1062 1 The words are expanded, or "$@@" if no words are given, d1065 4 d1104 1 a1104 1 These are implemented as built-in commands. d1115 2 a1116 2 [(] pattern ) list ;& [(] pattern ) list ;; d1131 2 a1132 2 .Dq list (which may be empty) d1142 1 a1142 1 is reached execution of the a1148 1 .Pp a1149 1 .Pp a1150 1 .Pp d1152 1 @ 1.160 log @Document the times builtin command, reported as lost in space by rudolf at eq.cz on tech-userlevel (July 15, 2017.) Also correct a typo, de-correct some entirely proper English so the doc remains written in American instead. And note that interactive mode is set when stdin & stderr are terminals, not stding and stdout. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.159 2017/07/01 05:11:57 wiz Exp $ d1531 18 a1548 7 and operate as they would in a C expression, except the unary .Dq ++ and .Dq -- operators (in both prefix and postfix forms) and the .Dq \&, (comma) operator, which are currently not supported. @ 1.159 log @Sort options (our default is 0..9AaBbZz). Fix markup problems and a typo. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.158 2017/06/30 23:48:50 kre Exp $ d34 1 a34 1 .Dd July 1, 2017 d116 2 a117 2 and output, of the shell are connected to a terminal (or if the d399 1 a399 1 If after procesing a command_string with the d2518 18 d3107 1 a3107 1 Initialised by the shell, ignoring any value from the environment, d3159 1 a3159 1 Initialised by the shell to the number of seconds since the Epoch @ 1.158 log @ Correct a markup typo (why did I not see this before the prev commit??) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.157 2017/06/30 23:07:29 kre Exp $ d37 1 a37 1 .ds flags abCeEfFhiILmnpquvVx d202 1 a202 1 Otheriwse, if d270 3 d286 8 a293 3 .It Fl C Em noclobber Don't overwrite existing files with .Dq > . a318 10 .It Fl E Em emacs Enable the built-in emacs style command line editor (disables .Fl V if it has been set). (See the .Sx Command Line Editing section below.) .It Fl f Em noglob Disable pathname expansion. d334 2 a341 2 .It Fl i Em interactive Force the shell to behave interactively. d345 2 d372 3 a374 1 cleared just before the next time the command line prompt (PS1) is written. a425 8 .It Fl v Em verbose The shell writes its input to standard error as it is read. Useful for debugging. .It Fl x Em xtrace Write each command to standard error (preceded by the expanded value of .Dq $PS4 ) before it is executed. Useful for debugging. d435 8 d477 1 a477 1 (expected by posix) or permits it. a3151 1 .Ev d3161 1 a3161 1 .Dq %T @ 1.157 log @ Omnibus manual update for prompt expansions and new variables. Throw in some random cleanups as a bonus. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.156 2017/06/28 13:46:06 kre Exp $ d221 1 a221 1 .Fc c @ 1.156 log @ Now libedit supports embedded mode switch sequence, improve sh support for them (adds PSlit variable to set the magic character). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.155 2017/06/27 12:43:44 kre Exp $ d34 1 a34 1 .Dd June 28, 2017 d36 2 a37 1 .ds flags abCEeFfhnuvxIimpqV d58 1 d88 1 a88 1 is in the process of being changed to conform with the d100 2 a101 2 It is the program that is running when a user logs into the system (although a user can select a different shell with the d193 8 a200 3 If command line arguments besides the options have been specified, then the shell treats the first argument as the name of a file from which to read commands (a shell script), and the remaining arguments are set as the d202 22 a223 2 Otherwise, the shell reads commands from its standard input. d236 8 d256 2 a257 2 .\" to give the indent as the _ in that case, and the fi ligature in .\" the former combine to make local_lineno slightly wider when printed d261 1 d265 2 a266 1 Export all variables assigned to. d273 1 a273 1 operand instead of from the standard input. d276 2 a277 2 operand and the positional parameters ($1, $2, etc.) set from the remaining argument operands. d288 3 d337 3 a339 2 Bind commands in functions to file system paths when the function is defined. When off, d346 1 d357 1 a357 1 in which the definition of the function occurs. d367 1 a367 1 If not interactive, read commands but do not execute them. d369 4 d393 9 a401 2 Read commands from standard input (set automatically if no file arguments are present). d403 4 a406 2 already started running (i.e. with .Ic set ) . d408 16 a423 2 Write a message to standard error when attempting to expand a variable that is not set, and if the shell is not interactive, exit immediately. d428 2 a429 2 Write each command to standard error (preceded by a .Sq +\ ) d455 1 a455 1 Enables closer adherence to the shell standard. d460 1 a460 1 That can be overridden by the d475 1 a475 1 (required by posix) or permits it. d482 12 d2984 10 d3055 15 d3073 4 d3078 6 a3083 1 Output before each line when execution trace (set -x) is enabled, d3086 9 d3111 40 d3156 33 a3410 7 .Ev PS1 , .Ev PS2 , and .Ev PS4 should be subject to parameter expansion before being displayed. .Pp @ 1.155 log @ Make one example more like a real world possibility (it still isn't, but is closer) - though the actual content is irrelevant to the point being made. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.154 2017/06/27 08:30:40 wiz Exp $ d34 1 a34 1 .Dd June 17, 2017 d2759 5 a2763 1 parameter, or using d2766 96 d2971 16 @ 1.154 log @Get rid of workarounds for ancient groff html backend. Simplify macro usage. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.153 2017/06/27 02:22:08 kre Exp $ d1025 1 a1025 1 { echo -n \*q hello \*q ; echo \*q world" ; } > greeting @ 1.153 log @ Properly support EDITRC - use it as (naming) the file when setting up libedit, and re-do the config whenever EDITRC is set. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.152 2017/06/17 07:50:35 kre Exp $ d248 1 a248 1 .Dq \*[Gt] . d259 1 a259 1 .Dq \*[Am]\*[Am] d435 1 a435 1 .Dl \*[Am] \*[Am]\*[Am] \&( \&) \&; ;; ;\*[Am] | || \*[Lt]newline\*[Gt] d437 1 a437 1 .Dl \*[Lt] \*[Gt] \*[Gt]| \*[Lt]\*[Lt] \*[Gt]\*[Gt] \*[Lt]\*[Am] \*[Gt]\*[Am] \*[Lt]\*[Lt]- \*[Lt]\*[Gt] d465 1 a465 1 .Dl $ ` \*q \e \*[Lt]newline\*[Gt] , d565 1 a565 1 .It Oo Ar n Oc Ns \*[Gt] Ar file d568 1 a568 1 .It Oo Ar n Oc Ns \*[Gt]| file d572 1 a572 1 .It Oo Ar n Oc Ns \*[Gt]\*[Gt] Ar file d575 1 a575 1 .It Oo Ar n Oc Ns \*[Lt] Ar file d580 1 a580 1 .It Oo Ar n1 Oc Ns \*[Lt]\*[Am] Ns Ar n2 d587 1 a587 1 .It Oo Ar n Oc Ns \*[Lt]\*[Am]- d590 1 a590 1 .It Oo Ar n1 Oc Ns \*[Gt]\*[Am] Ns Ar n2 d595 1 a595 1 .It Oo Ar n Oc Ns \*[Gt]\*[Am]- d597 1 a597 1 .It Oo Ar n Oc Ns \*[Lt]\*[Gt] Ar file d608 1 a608 1 .Li [n]\*[Lt]\*[Lt] delimiter d639 1 a639 1 .Dq \*[Lt]\*[Lt]\(mi d641 1 a641 1 .Dq \*[Lt]\*[Lt] , d796 1 a796 1 .Dl $ command1 2\*[Gt]\*[Am]1 | command2 d804 1 a804 1 next) to be executed sequentially; a \*[Am] causes asynchronous execution of d817 2 a818 2 .Ss Background Commands -- \*[Am] If a command is terminated by the control operator ampersand (\*[Am]), the d824 1 a824 1 .Dl command1 \*[Am] [command2 \*[Am] ...] d848 1 a848 1 .Dq \*[Am]\*[Am] d852 1 a852 1 .Dq \*[Am]\*[Am] d858 1 a858 1 .Dq \*[Am]\*[Am] d863 1 a863 1 .Dq true || echo bar \*[Am]\*[Am] echo baz d1025 1 a1025 1 { echo -n \*q hello \*q ; echo \*q world" ; } \*[Gt] greeting d1122 1 a1122 1 A positional parameter is a parameter denoted by a number (n \*[Gt] 0). d2399 2 a2400 2 .Do \&$1 Dc Ns \&, .Do \&$2 Dc Ns \&, d2760 1 a2760 1 .Xr editline 7 Ns \&'s d2866 1 a2866 1 .Dq \*[Gt] \ . @ 1.152 log @Changed the long name for the -L option from lineno_fn_relative to local_lineno as the latter seemed to be marginally more popular, and perhaps more importantly, is the same length as the peviously existing quietprofile option, which means the man page indentation for the list of options can return to (about) what it was before... (That is, less indented, which means more data/line, which means less lines of man page - a good thing!) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.151 2017/06/08 02:23:51 kre Exp $ d2753 9 d2768 25 @ 1.151 log @ Improve the (new) LINENO section, markup changes (with thanks to wiz@@ for assistace) and some better wording in a few placed. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.150 2017/06/07 13:49:48 wiz Exp $ d34 1 a34 1 .Dd June 4, 2017 d219 9 a227 1 .Bl -tag -width \-WXXlineno_fn_relativeXX -offset indent d305 1 a305 1 .It Fl L Em lineno_fn_relative d2932 1 a2932 1 .Ic lineno_fn_relative d2958 2 a2959 1 with the lines that surround the function definition. @ 1.150 log @New sentence, new line. Whitespace. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.149 2017/06/07 05:08:32 kre Exp $ d2871 5 a2875 2 should normally not ever be set, in this shell doing so reverses the effect of an earlier unset, d2879 1 a2879 1 should not be set again. d2902 5 a2906 3 there as well, however note that not all shells count interactive lines this way, it is wise to rely upon LINENO only having a useful value in a script, or a function. d2925 3 a2927 1 option) is set, when the function is defined, then the function d2946 1 a2946 1 .Dl local -I LINENO d2954 1 a2954 1 .Dl local Oo Fl I Ns Cm \&| Ns Fl N Ns Oc LINENO=value d2961 1 a2961 1 .Dl local -N LINENO @ 1.149 log @A better LINENO implementation. This version deletes (well, #if 0's out) the LINENO hack, and uses the LINENO var for both ${LINENO} and $((LINENO)). (Code to invert the LINENO hack when required, like when de-compiling the execution tree to provide the "jobs" command strings, is still included, that can be deleted when the LINENO hack is completely removed - look for refs to VSLINENO throughout the code. The var funclinno in parser.c can also be removed, it is used only for the LINENO hack.) This version produces accurate results: $((LINENO)) was made as accurate as the LINENO hack made ${LINENO} which is very good. That's why the LINENO hack is not yet completely removed, so it can be easily re-enabled. If you can tell the difference when it is in use, or not in use, then something has broken (or I managed to miss a case somewhere.) The way that LINENO works is documented in its own (new) section in the man page, so nothing more about that, or the new options, etc, here. This version introduces the possibility of having a "reference" function associated with a variable, which gets called whenever the value of the variable is required (that's what implements LINENO). There is just one function pointer however, so any particular variable gets at most one of the set function (as used for PATH, etc) or the reference function. The VFUNCREF bit in the var flags indicates which func the variable in question uses (if any - the func ptr, as before, can be NULL). I would not call the results of this perfect yet, but it is close. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.148 2017/06/06 22:38:52 kre Exp $ d309 1 a309 1 .Dq on d2927 2 a2928 1 function definition. Further, if @ 1.148 log @ Fix a typo (or rather a remnant of an earlier intent). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.147 2017/06/04 20:27:14 kre Exp $ d297 17 a313 13 .\" .It Fl L Em lineno_fn_relative .\" When set, before a function is defined, .\" causes the variable .\" .Ev LINENO .\" when used within the function, .\" to refer to the line number defined such that .\" first line of the function is line 1. .\" When reset, .\" .Ev LINENO .\" in a function refers to the line number within the file .\" in which the definition of the function occurs .\" (which can be the number of lines of shell input from standard input .\" when a function is defined interactively from the command prompt.) d2235 6 d2778 3 a2780 2 The value of this variable is automatically set by the shell, even if made readonly. d2854 147 @ 1.147 log @Make cd (really) do cd -P, and not just claim that is what it is doing while doing a half-hearted, broken, partial, version of cd -L instead. The latter (as the manual says) is not supported, what's more, it is an abomination, and should never be supported (anywhere.) Fix the doc so that the pretense that we notice when a path given crosses a symlink (and turns on printing of the destination directory) is claimed no more (that used to be true until late Dec 2016, but was changed). Now the print happens if -o cdprint is set, or if an entry from CDPATH that is not "" or "." is used (or if the "cd dest repl" cd cmd variant is used.) Fix CDPATH processing: avoid the magic '%' processing that is used for PATH and MAILPATH from corrupting CDPATH. The % magic (both variants) remains undocumented. Also, don't double the '/' if an entry in PATH or CDPATH ends in '/' (as in CDPATH=":/usr/src/"). A "cd usr.bin" used to do chdir("/usr/src//usr.bin"). No more. This is almost invisible, and relatively harmless, either way.... Also fix a bug where if a plausible destination directory in CDPATH was located, but the chdir() failed (eg: permission denied) and then a later "." or "" CDPATH entry succeeded, "print" mode was turned on. That is: cd /tmp; mkdir bin mkdir -p P/bin; chmod 0 P/bin CDPATH=/tmp/P: cd bin would cd to /tmp/bin (correctly) but print it (incorrectly). Also when in "cd dest replace" mode, if the result of the replacement generates '-' as the path named, as in: cd $PWD - then simply change to '-' (or attempt to, with CDPATH search), rather than having this being equivalent to "cd -") Because of these changes, the pwd command (and $PWD) essentially always acts as pwd -P, even when called as pwd -L (which is still the default.) That is, even more than it did before. Also fixed a (kind of minor) mem management error (CDPATH related) "whosoever shall padvance must stunalloc before repeating" (and the same for MAILPATH). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.146 2017/06/02 17:42:51 abhinav Exp $ d2222 1 a2222 1 .Fl U @ 1.146 log @Fix typo @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.145 2017/05/27 11:19:57 kre Exp $ d34 1 a34 1 .Dd May 12, 2017 d365 1 d1673 1 a1673 1 the first occurrence of d1677 1 a1677 1 If d1691 1 a1691 1 or its first (or only) component isn't dot or dot dot, d1723 5 a1727 2 that the user gave. These may be different either because the d1729 5 a1733 1 mechanism was used or because a symbolic link was crossed. @ 1.146.2.1 log @Pull up following revision(s) (requested by kre in ticket #5): bin/sh/cd.c: revision 1.48 bin/sh/eval.c: revision 1.141 bin/sh/exec.c: revision 1.48 bin/sh/exec.h: revision 1.25 bin/sh/mail.c: revisions 1.17, 1.18 bin/sh/sh.1: revision 1.147 Make cd (really) do cd -P, and not just claim that is what it is doing while doing a half-hearted, broken, partial, version of cd -L instead. The latter (as the manual says) is not supported, what's more, it is an abomination, and should never be supported (anywhere.) Fix the doc so that the pretense that we notice when a path given crosses a symlink (and turns on printing of the destination directory) is claimed no more (that used to be true until late Dec 2016, but was changed). Now the print happens if -o cdprint is set, or if an entry from CDPATH that is not "" or "." is used (or if the "cd dest repl" cd cmd variant is used.) Fix CDPATH processing: avoid the magic '%' processing that is used for PATH and MAILPATH from corrupting CDPATH. The % magic (both variants) remains undocumented. Also, don't double the '/' if an entry in PATH or CDPATH ends in '/' (as in CDPATH=":/usr/src/"). A "cd usr.bin" used to do chdir("/usr/src//usr.bin"). No more. This is almost invisible, and relatively harmless, either way.... Also fix a bug where if a plausible destination directory in CDPATH was located, but the chdir() failed (eg: permission denied) and then a later "." or "" CDPATH entry succeeded, "print" mode was turned on. That is: cd /tmp; mkdir bin mkdir -p P/bin; chmod 0 P/bin CDPATH=/tmp/P: cd bin would cd to /tmp/bin (correctly) but print it (incorrectly). Also when in "cd dest replace" mode, if the result of the replacement generates '-' as the path named, as in: cd $PWD - then simply change to '-' (or attempt to, with CDPATH search), rather than having this being equivalent to "cd -") Because of these changes, the pwd command (and $PWD) essentially always acts as pwd -P, even when called as pwd -L (which is still the default.) That is, even more than it did before. Also fixed a (kind of minor) mem management error (CDPATH related) "whosoever shall padvance must stunalloc before repeating" (and the same for MAILPATH). -- If we are going to keep the MAILPATH % hack, then at least do something rational. Since it isn't documented, what "rational" is is up for discussion, but what it did before was not it (it was nonsense...). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.146 2017/06/02 17:42:51 abhinav Exp $ d34 1 a34 1 .Dd June 4, 2017 a364 1 In a non-interactive shell this option has no effect. d1672 1 a1672 1 the first occurrence of the string d1676 1 a1676 1 Otherwise if d1690 1 a1690 1 and its first (or only) component isn't dot or dot dot, d1722 2 a1723 5 that the user gave, or always if the .Ic cdprint option is set. The destination may be different either because the d1725 1 a1725 5 mechanism was used .\" or because a symbolic link was crossed. or if the .Ar replace argument was used. @ 1.146.2.2 log @Pull up following revision(s) (requested by kre in ticket #15): bin/sh/sh.1: revision 1.148 Fix a typo (or rather a remnant of an earlier intent). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.146.2.1 2017/06/05 08:10:24 snj Exp $ d2222 1 a2222 1 .Fl N @ 1.146.2.3 log @Pull up following revision(s) (requested by kre in ticket #103): bin/kill/kill.c: 1.28 bin/sh/Makefile: 1.111-1.113 bin/sh/arith_token.c: 1.5 bin/sh/arith_tokens.h: 1.2 bin/sh/arithmetic.c: 1.3 bin/sh/arithmetic.h: 1.2 bin/sh/bltin/bltin.h: 1.15 bin/sh/cd.c: 1.49-1.50 bin/sh/error.c: 1.40 bin/sh/eval.c: 1.142-1.151 bin/sh/exec.c: 1.49-1.51 bin/sh/exec.h: 1.26 bin/sh/expand.c: 1.113-1.119 bin/sh/expand.h: 1.23 bin/sh/histedit.c: 1.49-1.52 bin/sh/input.c: 1.57-1.60 bin/sh/input.h: 1.19-1.20 bin/sh/jobs.c: 1.86-1.87 bin/sh/main.c: 1.71-1.72 bin/sh/memalloc.c: 1.30 bin/sh/memalloc.h: 1.17 bin/sh/mknodenames.sh: 1.4 bin/sh/mkoptions.sh: 1.3-1.4 bin/sh/myhistedit.h: 1.12-1.13 bin/sh/nodetypes: 1.16-1.18 bin/sh/option.list: 1.3-1.5 bin/sh/parser.c: 1.133-1.141 bin/sh/parser.h: 1.22-1.23 bin/sh/redir.c: 1.58 bin/sh/redir.h: 1.24 bin/sh/sh.1: 1.149-1.159 bin/sh/shell.h: 1.24 bin/sh/show.c: 1.43-1.47 bin/sh/show.h: 1.11 bin/sh/syntax.c: 1.4 bin/sh/syntax.h: 1.8 bin/sh/trap.c: 1.41 bin/sh/var.c: 1.56-1.65 bin/sh/var.h: 1.29-1.35 An initial attempt at implementing LINENO to meet the specs. Aside from one problem (not too hard to fix if it was ever needed) this version does about as well as most other shell implementations when expanding $((LINENO)) and better for ${LINENO} as it retains the "LINENO hack" for the latter, and that is very accurate. Unfortunately that means that ${LINENO} and $((LINENO)) do not always produce the same value when used on the same line (a defect that other shells do not share - aside from the FreeBSD sh as it is today, where only the LINENO hack exists and so (like for us before this commit) $((LINENO)) is always either 0, or at least whatever value was last set, perhaps by LINENO=${LINENO} which does actually work ... for that one line...) This could be corrected by simply removing the LINENO hack (look for the string LINENO in parser.c) in which case ${LINENO} and $((LINENO)) would give the same (not perfectly accurate) values, as do most other shells. POSIX requires that LINENO be set before each command, and this implementation does that fairly literally - except that we only bother before the commands which actually expand words (for, case and simple commands). Unfortunately this forgot that expansions also occur in redirects, and the other compound commands can also have redirects, so if a redirect on one of the other compound commands wants to use the value of $((LINENO)) as a part of a generated file name, then it will get an incorrect value. This is the "one problem" above. (Because the LINENO hack is still enabled, using ${LINENO} works.) This could be fixed, but as this version of the LINENO implementation is just for reference purposes (it will be superseded within minutes by a better one) I won't bother. However should anyone else decide that this is a better choice (it is probably a smaller implementation, in terms of code & data space then the replacement, but also I would expect, slower, and definitely less accurate) this defect is something to bear in mind, and fix. This version retains the *BSD historical practice that line numbers in functions (all functions) count from 1 from the start of the function, and elsewhere, start from 1 from where the shell started reading the input file/stream in question. In an "eval" expression the line number starts at the line of the "eval" (and then increases if the input is a multi-line string). Note: this version is not documented (beyond as much as LINENO was before) hence this slightly longer than usual commit message. A better LINENO implementation. This version deletes (well, #if 0's out) the LINENO hack, and uses the LINENO var for both ${LINENO} and $((LINENO)). (Code to invert the LINENO hack when required, like when de-compiling the execution tree to provide the "jobs" command strings, is still included, that can be deleted when the LINENO hack is completely removed - look for refs to VSLINENO throughout the code. The var funclinno in parser.c can also be removed, it is used only for the LINENO hack.) This version produces accurate results: $((LINENO)) was made as accurate as the LINENO hack made ${LINENO} which is very good. That's why the LINENO hack is not yet completely removed, so it can be easily re-enabled. If you can tell the difference when it is in use, or not in use, then something has broken (or I managed to miss a case somewhere.) The way that LINENO works is documented in its own (new) section in the man page, so nothing more about that, or the new options, etc, here. This version introduces the possibility of having a "reference" function associated with a variable, which gets called whenever the value of the variable is required (that's what implements LINENO). There is just one function pointer however, so any particular variable gets at most one of the set function (as used for PATH, etc) or the reference function. The VFUNCREF bit in the var flags indicates which func the variable in question uses (if any - the func ptr, as before, can be NULL). I would not call the results of this perfect yet, but it is close. Unbreak (at least) i386 build .... I have no idea why this built for me on amd64 (problem was missing prototype for snprintf witout ) While here, add some (DEBUG mode only) tracing that proved useful in solving another problem. Set the line number before expanding args, not after. As the line_number would have usually been set earlier, this change is mostly an effective no-op, but it is better this way (just in case) - not observed to have caused any problems. Undo some over agressive fixes for a (pre-commit) bug that did not need these changes to be fixed - and these cause problems in another absurd use case. Either of these issues is unlikely to be seen by anyone who isn't an idiot masochist... PR bin/52280 removescapes_nl in expari() even when not quoted, CRTNONL's appear regardless of quoting (unlike CTLESC). New sentence, new line. Whitespace. Improve the (new) LINENO section, markup changes (with thanks to wiz@@ for assistace) and some better wording in a few placed. I am an idiot... revert the previous unintended commit. Remove some left over baggage from the LINENO v1 implementation that didn't get removed with v2, and should have. This would have had (I think, without having tested it) one very minor effect on the way LINENO worked in the v2 implementation, but my guess is it would have taken a long time before anyone noticed... Correct spelling in comments of DEBUG only code... (Perhaps) temporary fix to pkgtools (cwrappers) build (configure). Expanding `` containing \ \n sequences looks to have been giving problems. I don't think this is the correct fix, but it will do no worse harm than (perhaps) incorrectly calculating LINENO in this kind of (rare) circumstance. I'll look and see if there should be a better fix later. s/volatile/const/ -- wonderful how opposites attract like this. NFC (normal use) - DEBUG only change, when showing empty arg list don't omit terminating \n. Free stack memory in a couple of obscure cases where it wasn't being done (one in probably dead code that is never compiled, the other in a very rare error case.) Since it is stack memory it wasn't lost in any case, just held longer than needed. Many internal memory management type fixes. PR bin/52302 (core dump with interactive shell, here doc and error on same line) is fixed. (An old bug.) echo "$( echo x; for a in $( seq 1000 ); do printf '%s\n'; done; echo y )" consistently prints 1002 lines (x, 1000 empty ones, then y) as it should (And you don't want to know what it did before, or why.) (Another old one.) (Recently added) Problems with ~ expansion fixed (mem management related). Proper fix for the cwrappers configure problem (which includes the quick fix that was done earlier, but extends upon that to be correct). (This was another newly added problem.) And the really devious (and rare) old bug - if STACKSTRNUL() needs to allocate a new buffer in which to store the \0, calculate the size of the string space remaining correctly, unlike when SPUTC() grows the buffer, there is no actual data being stored in the STACKSTRNUL() case - the string space remaining was calculated as one byte too few. That would be harmless, unless the next buffer also filled, in which case it was assumed that it was really full, not one byte less, meaning one junk char (a nul, or anything) was being copied into the next (even bigger buffer) corrupting the data. Consistent use of stalloc() to allocate a new block of (stack) memory, and grabstackstr() to claim a block of (stack) memory that had already been occupied but not claimed as in use. Since grabstackstr is implemented as just a call to stalloc() this is a no-op change in practice, but makes it much easier to comprehend what is really happening. Previous code sometimes used stalloc() when the use case was really for grabstackstr(). Change grabstackstr() to actually use the arg passed to it, instead of (not much better than) guessing how much space to claim, More care when using unstalloc()/ungrabstackstr() to return space, and in particular when the stack must be returned to its previous state, rather than just returning no-longer needed space, neither of those work. They also don't work properly if there have been (really, even might have been) any stack mem allocations since the last stalloc()/grabstackstr(). (If we know there cannot have been then the alloc/release sequence is kind of pointless.) To work correctly in general we must use setstackmark()/popstackmark() so do that when needed. Have those also save/restore the top of stack string space remaining. [Aside: for those reading this, the "stack" mentioned is not in any way related to the thing used for maintaining the C function call state, ie: the "stack segment" of the program, but the shell's internal memory management strategy.] More comments to better explain what is happening in some cases. Also cleaned up some hopelessly broken DEBUG mode data that were recently added (no effect on anyone but the poor semi-human attempting to make sense of it...). User visible changes: Proper counting of line numbers when a here document is delimited by a multi-line end-delimiter, as in cat << 'REALLY END' here doc line 1 here doc line 2 REALLY END (which is an obscure case, but nothing says should not work.) The \n in the end-delimiter of the here doc (the last one) was not incrementing the line number, which from that point on in the script would be 1 too low (or more, for end-delimiters with more than one \n in them.) With tilde expansion: unset HOME; echo ~ changed to return getpwuid(getuid())->pw_home instead of failing (returning ~) POSIX says this is unspecified, which makes it difficult for a script to compensate for being run without HOME set (as in env -i sh script), so while not able to be used portably, this seems like a useful extension (and is implemented the same way by some other shells). Further, with HOME=; printf %s ~ we now write nothing (which is required by POSIX - which requires ~ to expand to the value of $HOME if it is set) previously if $HOME (in this case) or a user's directory in the passwd file (for ~user) were a null STRING, We failed the ~ expansion and left behind '~' or '~user'. Changed the long name for the -L option from lineno_fn_relative to local_lineno as the latter seemed to be marginally more popular, and perhaps more importantly, is the same length as the peviously existing quietprofile option, which means the man page indentation for the list of options can return to (about) what it was before... (That is, less indented, which means more data/line, which means less lines of man page - a good thing!) Cosmetic changes to variable flags - make their values more suited to my delicate sensibilities... (NFC). Arrange not to barf (ever) if some turkey makes _ readonly. Do this by adding a VNOERROR flag that causes errors in var setting to be ignored (intended use is only for internal shell var setting, like of "_"). (nb: invalid var name errors ignore this flag, but those should never occur on a var set by the shell itself.) From FreeBSD: don't simply discard memory if a variable is not set for any reason (including because it is readonly) if the var's value had been malloc'd. Free it instead... NFC - DEBUG changes, update this to new TRACE method. KNF - white space and comment formatting. NFC - DEBUG mode only change - convert this to the new TRACE() format. NFC - DEBUG mode only change - complete a change made earlier (marking the line number when included in the trace line tag to show whether it comes from the parser, or the elsewhere as they tend to be quite different). Initially only one case was changed, while I pondered whether I liked it or not. Now it is all done... Also when there is a line tag at all, always include the root/sub-shell indicator character, not only when the pid is included. NFC: DEBUG related comment change - catch up with reality. NFC: DEBUG mode only change. Fix botched cleanup of one TRACE(). "b" more forgiving when sorting options to allow reasonable (and intended) flexibility in option.list format. Changes nothing for current option.list. Now that excessive use of STACKSTRNUL has served its purpose (well, accidental purpose) in exposing the bug in its implementation, go back to not using it when not needed for DEBUG TRACE purposes. This change should have no practical effect on either a DEBUG shell (where the STACKSTRNUL() calls remain) or a non DEBUG shell where they are not needed. Correct the initial line number used for processing -c arg strings. (It was inheriting the value from end of profile file processing) - I didn't notice before as I usually test with empty or no profile files to avoid complications. Trivial change which should have very limited impact. Fix from FreeBSD (applied there in July 2008...) Don't dump core with input like sh -c 'x=; echo >&$x' - that is where the word after a >& or <& redirect expands to nothing at all. Another fix from FreeBSD (this one from April 2009). When processing a string (as in eval, trap, or sh -c) don't allow trailing \n's to destroy the exit status of the last command executed. That is: sh -c 'false ' echo $? should produce 1, not 0. It is amazing what nonsense appears to work sometimes... (all my nonsense too!) Two bugs here, one benign because of the way the script is used. The other hidden by NetBSD's sort being stable, and the data not really requiring sorting at all... So as it happens these fixes change nothing, but they are needed anyway. (The contents of the generated file are only used in DEBUG shells, so this is really even less important than it seems.) Another ancient (highly improbable) bug bites the dust. This one caused by incorrect macro usage (ie: using the wrong one) which has been in the sources since version 1.1 (ie: forever). Like the previous (STACKSTRNUL) bug, the probability of this one actually occurring has been infinitesimal but the LINENO code increases that to infinitesimal and a smidgen... (or a few, depending upon usage). Still, apparently that was enough, Kamil Rytarowski discovered that the zsh configure script (damn competition!) managed to trigger this problem. source .editrc after we initialize so that commands persist! Make arg parsing in kill POSIX compatible with POSIX (XBD 2.12) by parsing the way getopt(3) would, if only it could handle the (required) -signumber and -signame options. This adds two "features" to kill, -ssigname and -lstatus now work (ie: one word with all of the '-', the option letter, and its value) and "--" also now works (kill -- -pid1 pid2 will not attempt to send the pid1 signal to pid2, but rather SIGTERM to the pid1 process group and pid2). It is still the case that (apart from --) at most 1 option is permitted (-l, -s, -signame, or -signumber.) Note that we now have an ambiguity, -sname might mean "-s name" or send the signal "sname" - if one of those turns out to be valid, that will be accepted, otherwise the error message will indicate that "sname" is not a valid signal name, not that "name" is not. Keeping the "-s" and signal name as separate words avoids this issue. Also caution: should someone be weird enough to define a new signal name (as in the part after SIG) which is almost the same name as an existing name that starts with 'S' by adding an extra 'S' prepended (eg: adding a SIGSSYS) then the ambiguity problem becomes much worse. In that case "kill -ssys" will be resolved in favour of the "-s" flag being used (the more modern syntax) and would send a SIGSYS, rather that a SIGSSYS. So don't do that. While here, switch to using signalname(3) (bye bye NSIG, et. al.), add some constipation, and show a little pride in formatting the signal names for "kill -l" (and in the usage when appropriate -- same routine.) Respect COLUMNS (POSIX XBD 8.3) as primary specification of the width (terminal width, not number of columns to print) for kill -l, a very small value for COLUMNS will cause kill -l output to list signals one per line, a very large value will cause them all to be listed on one line.) (eg: "COLUMNS=1 kill -l") TODO: the signal printing for "trap -l" and that for "kill -l" should be switched to use a common routine (for the sh builtin versions.) All changes of relevance here are to bin/kill - the (minor) changes to bin/sh are only to properly expose the builtin version of getenv(3) so the builtin version of kill can use it (ie: make its prototype available.) Properly support EDITRC - use it as (naming) the file when setting up libedit, and re-do the config whenever EDITRC is set. Get rid of workarounds for ancient groff html backend. Simplify macro usage. Make one example more like a real world possibility (it still isn't, but is closer) - though the actual content is irrelevant to the point being made. Add literal prompt support this allows one to do: CA="$(printf '\1')" PS1="${CA}$(tput bold)${CA}\$${CA}$(tput sgr0)${CA} " Now libedit supports embedded mode switch sequence, improve sh support for them (adds PSlit variable to set the magic character). NFC: DEBUG only change - provide an externally visible (to the DEBUG sh internals) interface to one of the internal (private to trace code) functions Include redirections in trace output from "set -x" Implement PS1, PS2 and PS4 expansions (variable expansions, arithmetic expansions, and if enabled by the promptcmds option, command substitutions.) Implement a bunch of new shell environment variables. many mostly useful in prompts when expanded at prompt time, but all available for general use. Many of the new ones are not available in SMALL shells (they work as normal if assigned, but the shell does not set or use them - and there is no magic in a SMALL shell (usually for install media.)) Omnibus manual update for prompt expansions and new variables. Throw in some random cleanups as a bonus. Correct a markup typo (why did I not see this before the prev commit??) Sort options (our default is 0..9AaBbZz). Fix markup problems and a typo. Make $- list flags in the same order they appear in sh(1) Do a better job of detecting the error in pkgsrc/devel/libbson-1.6.3's configure script, ie: $(( which is intended to be a sub-shell in a command substitution, but is an arith subst instead, it needs to be written $( ( to do as intended. Instead of just blindly carrying on to find the missing )) somewhere, anywhere, give up as soon as we have seen an unbalanced ')' that isn't immediately followed by another ')' which in a valid arith subst it always would be. While here, there has been a comment in the code for quite a while noting a difference in the standard between the text descr & grammar when it comes to the syntax of case statements. Add more comments to explain why parsing it as we do is in fact definitely the correct way (ie: the grammar wins arguments like this...). DEBUG and white space changes only. Convert TRACE() calls for DEBUg mode to the new style. NFC (when not debugging sh). Mostly DEBUG and white space changes. Convert DEEBUG TRACE() calls to the new format. Also #if 0 a function definition that is used nowhere. While here, change the function of pushfile() slightly - it now sets the buf pointer in the top (new) input descriptor to NULL, instead of simply leaving it - code that needs a buffer always (before and after) must malloc() one and assign it after the call. But code which does not (which will be reading from a string or similar) now does not have to explicitly set it to NULL (cleaner interface.) NFC intended (or observed.) DEBUG changes: convert DEBUG TRACE() calls to new format. ALso, cause exec failures to always cause the shell to exit with status 126 or 127, whatever the cause. 127 is intended for lookup failures (and is used that way), 126 is used for anything else that goes wrong (as in several other shells.) We no longer use 2 (more easily confused with an exit status of the command exec'd) for shell exec failures. DEBUG only changes. Convert the TRACE() calls in the remaining files that still used it to the new format. NFC. Fix a reference after free (and consequent nonsense diagnostic for attempts to set readonly variables) I added in 1.60 by incompletely copying the FreeBSD fix for the lost memory issue. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.146.2.2 2017/06/09 16:53:39 snj Exp $ d34 1 a34 1 .Dd July 1, 2017 d36 1 a36 2 .\" everything except c o and s (keep them ordered) .ds flags abCEeFfhIiLmnpquVvx a56 1 .Op Fl s d86 1 a86 1 is in the process of being changed to conform more closely to the d98 2 a99 2 A shell is the program that is running when a user logs into the system. (Users can select which shell is executed for them at login with the d191 3 a193 8 If command line arguments besides the options have been specified, and neither .Fl c nor .Fl s was given, then the shell treats the first argument as the name of a file from which to read commands (a shell script). This also becomes $0 and the remaining arguments are set as the d195 2 a196 22 Otherwise, if .Fl c was given, then the first argument, which must exist, is taken to be a string of .Nm commands to execute. Then if any additional arguments follow the command string, those arguments become $0, $1, ... Otherwise, if additional arguments were given (which implies that .Fl s was set) those arguments become $1, $2, ... If $0 has not been set by the preceding processing, it will be set to argv[0] as passed to the shell, which will usually be the name of the shell itself. If .Fl s was given, or if neither .Fl c nor any additional (non-option) arguments were present, the shell reads commands from its standard input. a208 8 Some options have only a long name, they are described after the flag options, they are used with .Fl o or .Cm +o only, either on the command line, or with the .Ic set built-in command. d219 1 a219 10 .\" .\" strlen("quietprofile") == strlen("local_lineno"): pick the latter .\" to give the indent as the _ in local_lineno, and the fi ligature in .\" quietprofile combine to make "local_lineno' slightly wider when printed .\" (in italics) in a variable width font. Probably should test the actual .\" widths and use the wider, but I am not sure if mandoc is up to that... .\" (and I don't know how to get at the font that will be used easily anyway!) .\" The X's just provide a little extra space. .Bl -tag -width \-WXXlocal_linenoXX -offset indent .\" d221 1 a221 2 Automatically export any variable to which a value is assigned while this flag is set. a224 3 .It Fl C Em noclobber Don't overwrite existing files with .Dq > . d228 1 a228 1 operand instead of, or in addition to, from the standard input. d231 2 a232 2 operand if given, and the positional parameters ($1, $2, etc.) set from the remaining argument operands, if any. d238 3 a240 8 .It Fl E Em emacs Enable the built-in emacs style command line editor (disables .Fl V if it has been set). (See the .Sx Command Line Editing section below.) a242 3 If interactive, and an untested command fails, cease all processing of the current command and return to prompt for a new command. d251 1 a251 1 .Dq && d263 10 a287 2 .It Fl f Em noglob Disable pathname expansion. d289 2 a290 3 Functions defined while this option is set will have paths bound to commands to be executed by the function at the time of the definition. When off when a function is defined, d293 2 d297 13 a309 20 (After a large number of consecutive EOFs the shell will exit anyway.) .It Fl i Em interactive Force the shell to behave interactively. .It Fl L Em local_lineno When set, before a function is defined, causes the variable .Ev LINENO when used within the function, to refer to the line number defined such that first line of the function is line 1. When reset, .Ev LINENO in a function refers to the line number within the file within which the definition of the function occurs. This option defaults to .Dq on in this shell. For more details see the section .Sx LINENO below. d313 1 a313 1 Read and parse commands, but do not execute them. a314 6 If .Fl n becomes set in an interactive shell, it will automatically be cleared just before the next time the command line prompt .Pq Ev PS1 is written. d335 2 a336 9 Read commands from standard input (set automatically if neither .Fl c nor file arguments are present). If after procesing a command_string with the .Fl c option, the shell has not exited, and the .Fl s option is set, it will continue reading more commands from standard input. d338 2 a339 4 already started reading from the command_file, or from standard input. Note that the .Fl s flag being set does not cause the shell to be interactive. d341 10 a350 16 Write a message to standard error when attempting to obtain a value from a variable that is not set, and if the shell is not interactive, exit immediately. For interactive shells, instead return immediately to the command prompt and read the next command. Note that expansions (described later, see .Sx Word Expansions below) using the .Sq \&+ , .Sq \&\- , .Sq \&= , or .Sq \&? operators test if the variable is set, before attempting to obtain its value, and hence are unaffected by .Fl u . a359 8 .It Fl v Em verbose The shell writes its input to standard error as it is read. Useful for debugging. .It Fl x Em xtrace Write each command to standard error (preceded by the expanded value of .Dq $PS4 ) before it is executed. Useful for debugging. d374 1 a374 1 Enables closer adherence to the POSIX shell standard. d379 1 a379 1 That can be overridden (set or reset) by the d394 1 a394 1 (expected by POSIX) or permits it. a400 12 .It "\ \ " Em promptcmds Allows command substitutions (as well as parameter and arithmetic expansions, which are always performed) upon the prompt strings .Ev PS1 , .Ev PS2 , and .Ev PS4 each time, before they are output. This option should not be set until after the prompts have been set (or verified) to avoid accidentally importing unwanted command substitutions from the environment. d423 1 a423 1 .Dl & && \&( \&) \&; ;; ;& | || d425 1 a425 1 .Dl < > >| << >> <& >& <<- <> d453 1 a453 1 .Dl $ ` \*q \e , d553 1 a553 1 .It Oo Ar n Oc Ns > Ar file d556 1 a556 1 .It Oo Ar n Oc Ns >| file d560 1 a560 1 .It Oo Ar n Oc Ns >> Ar file d563 1 a563 1 .It Oo Ar n Oc Ns < Ar file d568 1 a568 1 .It Oo Ar n1 Oc Ns <& Ns Ar n2 d575 1 a575 1 .It Oo Ar n Oc Ns <&- d578 1 a578 1 .It Oo Ar n1 Oc Ns >& Ns Ar n2 d583 1 a583 1 .It Oo Ar n Oc Ns >&- d585 1 a585 1 .It Oo Ar n Oc Ns <> Ar file d596 1 a596 1 .Li [n]<< delimiter d627 1 a627 1 .Dq <<\(mi d629 1 a629 1 .Dq << , d784 1 a784 1 .Dl $ command1 2>&1 | command2 d792 1 a792 1 next) to be executed sequentially; a & causes asynchronous execution of d805 2 a806 2 .Ss Background Commands -- & If a command is terminated by the control operator ampersand (&), the d812 1 a812 1 .Dl command1 & [command2 & ...] d836 1 a836 1 .Dq && d840 1 a840 1 .Dq && d846 1 a846 1 .Dq && d851 1 a851 1 .Dq true || echo bar && echo baz d1013 1 a1013 1 { echo -n \*qhello \*q ; echo \*qworld\*q ; } > greeting d1110 1 a1110 1 A positional parameter is a parameter denoted by a number (n > 0). a2230 6 .Pp See the section .Sx LINENO below for details of the effects of making the variable .Ev LINENO local. d2381 2 a2382 2 .Dq \&$1 , .Dq \&$2 , a2734 109 Also see .Xr editrc 5 for the commands that can be given to configure .Xr editline 7 in the file named by the .Ev EDITRC parameter, or a file used with the .Ic inputrc built-in command, or using .Xr editline 7 Ap s configuration command line. .Pp When command line editing is enabled, the .Xr editline 7 functions control printing of the .Ev PS1 and .Ev PS2 prompts when required. As, in this mode, the command line editor needs to keep track of what characters are in what position on the command line, care needs to be taken when setting the prompts. Normal printing characters are handled automatically, however mode setting sequences, which do not actually display on the terminal, need to be identified to .Xr editline 7 . This is done, when needed, by choosing a character that is not needed anywhere in the prompt, including in the mode setting sequences, any single character is acceptable, and assigning it to the shell parameter .Ev PSlit . Then that character should be used, in pairs, in the prompt string. Between each pair of .Ev PSlit characters are mode setting sequences, which affect the printing attributes of the following (normal) characters of the prompt, but do not themselves appear visibly, nor change the terminal's cursor position. .Pp Each such sequence, that is .Ev PSlit character, mode setting character sequence, and another .Ev PSlit character, must currently be followed by at least one following normal prompt character, or it will be ignored. That is, a .Ev PSlit character cannot be the final character of .Ev PS1 or .Ev PS2 , nor may two .Ev PSlit delimited sequences appear adjacent to each other. Each sequence can contain as many mode altering sequences as are required however. Only the first character from .Ev PSlit will be used. When set .Ev PSlit should usually be set to a string containing just one character, then it can simply be embedded in .Ev PS1 (or .Ev PS2 ) as in .Dl PS1="${PSlit}mset${PSlit}XYZ${PSlit}mclr${PSlit}ABC" The prompt visible will be .Dq XYZABC with the .Dq XYZ part shown according as defined by the mode setting characters .Dq mset , and then cleared again by .Dq mclr . See .Xr tput 1 for one method to generate appropriate mode sequences. Note that both parts, XYZ and ABC, must each contain at least one character. .Pp If .Ev PSlit is unset, which is its initial state, or set to a null string, no literal character will be defined, and all characters of the prompt strings will be assumed to be visible characters (which includes spaces etc.) To allow smooth use of prompts, without needing redefinition, when .Xr editline 7 is disabled, the character chosen should be one which will be ignored by the terminal if received, as when .Xr edlitline 7 is not in use, the prompt strings are simply written to the terminal. For example, setting: .Bd -compact -literal -offset left PSlit="$(printf\ '\e1')" PS1="${PSlit}$(tput\ bold\ blink)${PSlit}\e$${PSlit}$(tput\ sgr0)${PSlit}\ " .Ed will arrange for the primary prompt to be a bold blinking dollar sign, if supported by the current terminal, followed by an (ordinary) space, and, as the SOH (Control-A) character ('\e1') will not normally affect a terminal, this same prompt will usually work with .Xr editline 7 enabled or disabled. a2740 25 .It Ev EDITRC Gives the name of the file containing commands for .Xr editline 7 . See .Xr editrc 5 for possible content and format. The file is processed, when in interactive mode with command line editing enabled, whenever .Ev EDITRC is set (even with no actual value change,) and if command line editing changes from disabled to enabled, or the editor style used is changed. (See the .Fl E and .Fl V options of the .Ic set builtin command, described in .Sx Built-ins above, which are documented further above in .Sx Argument List Processing . ) If unset .Dq $HOME/.editrc is used. a2750 10 .It Ev HOSTNAME Set to the current hostname of the system, as returned by .Xr gethostname 3 . This is obtained each time .Ev HOSTNAME is expanded, so changes to the system's name are reflected without further action. If unset, it returns nothing. Setting it does nothing except reverse the effect of an earlier .Ic unset . d2768 2 a2769 3 See the section .Sx LINENO below for more details. a2810 15 This string is subject to parameter, arithmetic, and if enabled by setting the .Ic promptcmds option, command substitution before being output. During execution of commands used by command substitution, execution tracing, the .Ic xtrace .Ic ( set Fl x ) option is temporarily disabled. If .Ic promptcmds is not set and the prompt string uses command substitution, the prompt used will be an appropriate error string. For other expansion errors, a message will be output, and the unexpanded string will then be used as the prompt. d2813 1 a2813 5 .Dq > \ . After expansion (as for .Ev PS1 ) it is written whenever more input is required to complete the current command. d2815 1 a2815 6 Output, after expansion like .Ev PS1 , before each line when execution trace .Ic ( set Fl x ) is enabled. .Ev PS4 a2817 64 .It Ev PSc Initialised by the shell, ignoring any value from the environment, to a single character string, either .Sq \&# or .Sq \&$ , depending upon whether the current user is the superuser or not. This is intended for use when building a custom .Ev PS1 . .It Ev PSlit Defines the character which may be embedded in pairs, in .Ev PS1 or .Ev PS2 to indicate to .Xr editline 7 that the characters between each pair of occurrences of the .Ev PSlit character will not appear in the visible prompt, and will not cause the terminal's cursor to change position, but rather set terminal attributes for the following prompt character(s) at least one of which must be present. See .Sx Command Line Editing above for more information. .It Ev RANDOM Returns a different pseudo-random integer, in the range [0,32767] each time it is accessed. .Ev RANDOM can be assigned an integer value to seed the PRNG. If the value assigned is a constant, then the sequence of values produces on subsequent references of .Ev RANDOM will repeat after the next time the same constant is assigned. Note, this is not guaranteed to remain constant from one version of the shell to another \(en the PRNG algorithm, or seeding method is subject to change. If .Ev RANDOM is assigned an empty value (null string) then the next time .Ev RANDOM is accessed, it will be seeded from a more genuinely random source. The sequence of pseudo-random numbers generated will not be able to be generated again (except by luck, whether good or bad, depends!) This is also how the initial seed is generated, if none has been assigned before .Ev RANDOM is first accessed after shell initialization. .It Ev SECONDS Returns the number of seconds since the current shell was started. Attempts to set this variable are ignored. If unset, it remains unset, and returns nothing, unless set again. .It Ev START_TIME Initialised by the shell to the number of seconds since the Epoch (see .Xr localtime 3 ) when the shell was started. The value of .Dl $(( Ns Ev START_TIME + Ev SECONDS Ns )) represents the current time, if .Ev START_TIME has not been modified, and .Ev SECONDS is not unset. a2822 33 .It Ev ToD When referenced, uses the value of .Ev ToD_FORMAT (or .Dq \&%T if .Ev ToD_FORMAT is unset) as the format argument to .Xr strftime 3 to encode the current time of day, in the time zone defined by .Ev TZ if set, or current local time if not, and returns the result. If unset .Ev ToD returns nothing. Setting it has no effect, other than to reverse the effect of an earlier .Ic unset . .It Ev ToD_FORMAT Can be set to the .Xr strftime 3 format string to be used when expanding .Ev ToD . Initially unset. .It Ev TZ If set, gives the time zone (see .Xr localtime 3 , .Xr environ 7 ) to use when formatting .Ev ToD and if exported, other utilities that deal with times. If unset, the system's local wall clock time zone is used. a2842 156 .Ss Ev LINENO .Ev LINENO is in many respects a normal shell variable, containing an integer value. and can be expanded using any of the forms mentioned above which can be used for any other variable. .Pp .Ev LINENO can be exported, made readonly (which prevents attempts to assign to it, and to unset it, but which does not change the value, that is the current line number, from being obtained when .Ev LINENO is referenced,) and can be unset. All of those act as they would with any other variable. However, .Ev LINENO should normally not ever be set or unset. In this shell setting .Ev LINENO reverses the effect of an earlier .Ic unset , but does not otherwise affect the value obtained. If unset, .Ev LINENO should not normally be set again, doing so is not portable. If .Ev LINENO is set or unset, different shells act differently. The value of .Ev LINENO is never imported from the environment when the shell is started, though if present there, as with any other variable, .Ev LINENO will be exported by this shell. .Pp .Ev LINENO is set automatically by the shell to be the number of the source line on which it occurs. When exported, .Ev LINENO is exported with its value set to the line number it would have had had it been referenced on the command line of the command to which it is exported. Line numbers are counted from 1, which is the first line the shell reads from any particular file. For this shell, standard input, including in an interactive shell, the user's terminal, is just another file and lines are counted there as well. However note that not all shells count interactive lines this way, it is not wise to rely upon .Ev LINENO having a useful value, except in a script, or a function. .Pp The role of .Ev LINENO in functions is less clear. In some shells, .Ev LINENO continues to refer to the line number in the script which defines the function, in others lines count from one within the function, always (and resume counting normally once the function definition is complete) and others count in functions from one if the function is defined interactively, but otherwise just reference the line number in the script in which the function is defined. This shell gives the user the option to choose. If the .Fl L flag (the .Ic local_lineno option, see .Sx Argument List Processing ) is set, when the function is defined, then the function defaults to counting lines with one being the first line of the function. When the .Fl L flag is not set, the shell counts lines in a function definition in the same continuous sequence as the lines that surround the function definition. Further, if .Ev LINENO is made local (see .Sx Built-ins above) inside the function, the function can decide which behavior it prefers. If .Ev LINENO is made local and inherited, and not given a value, as in .Dl local Fl I Ev LINENO then from that point in the function, .Ev LINENO will give the line number as if lines are counted in sequence with the lines that surround the function definition (and any other function definitions in which this is nested.) If .Ev LINENO is made local, and in that same command, given a value, as .Dl local Oo Fl I Ns | Ns Fl N Oc Ev LINENO Ns = Ns Ar value then .Ev LINENO will give the line number as if lines are counted from one from the beginning of the function. The value nominally assigned in this case is irrelevant, and ignored. For completeness, if lineno is made local and unset, as in .Dl local Fl N Ev LINENO then .Ev LINENO is simply unset inside the function, and gives no value at all. .Pp Now for some technical details. The line on which .Ev LINENO occurs in a parameter expansion, is the line that contains the .Sq \&$ that begins the expansion of .Ev LINENO . In the case of nested expansions, that .Sq \&$ is the one that actually has .Ev LINENO as its parameter. In an arithmetic expansion, where no .Sq \&$ is used to evaluate .Ev LINENO but .Ev LINENO is simply referenced as a variable, then the value is the line number of the line that contains the .Sq L of .Ev LINENO . For functions line one of the function definition (when relevant) is the line that contains the first character of the function name in the definition. When exported, the line number of the command is the line number where the first character of the word which becomes the command name occurs. .Pp When the shell opens a new file, for any reason, it counts lines from one in that file, and then resumes its original counting once it resumes reading the previous input stream. When handling a string passed to .Ic eval the line number starts at the line on which the string starts, and then if the string contains internal newline characters, those characters increase the line number. This means that references to .Ev LINENO in such a case can produce values larger than would be produced by a reference on the line after the .Ic eval . d2889 7 @ 1.146.2.4 log @Pull up following revision(s) (requested by kre in ticket #310): bin/sh/expand.c: revision 1.121 bin/sh/sh.1: revision 1.167 via patch Three fixes and a change to ~ expansions 1. A serious bug introduced 3 1/2 months ago (approx) (rev 1.116) which broke all but the simple cases of ~ expansions is fixed (amazingly, given the magnitude of this problem, no-one noticed!) 2. An ancient bug (probably from when ~ expansion was first addedin 1994, and certainly is in NetBSD-6 vintage shells) where ${UnSeT:-~} (and similar) does not expand the ~ is fixed (note that ${UnSeT:-~/} does expand, this should give a clue to the cause of the problem. 3. A fix/change to make the effects of ~ expansions on ${UnSeT:=whatever} identical to those in UnSeT=whatever In particular, with HOME=/foo ${UnSeT:=~:~} now assigns, and expands to, /foo:/foo rather than ~:~ just as VAR=~:~ assigns /foo:/foo to VAR. Note this is even after the previous fix (ie: appending a '/' would not change the results here.) It is hard to call this one a bug fix for certain (though I believe it is) as many other shells also produce different results for the ${V:=...} expansions than they do for V=... (though not all the same as we did). POSIX is not clear about this, expanding ~ after : in VAR=whatever assignments is clear, whether ${U:=whatever} assignments should be treated the same way is not stated, one way or the other. 4. Change to make ':' terminate the user name in a ~ expansion in all cases, not only in assignments. This makes sense, as ':' is one character that cannot occur in user names, no matter how otherwise weird they become. bash (incl in posix mode) ksh93 and bosh all act this way, whereas most other shells (and POSIX) do not. Because this is clearly an extension to POSIX, do this one only when not in posix mode (not set -o posix). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.146.2.3 2017/07/23 14:58:14 snj Exp $ d34 1 a34 1 .Dd October 6, 2017 a474 4 whether a colon (:) terminates the user name in tilde (~) expansions other than in assignment statements .Dq ( no in posix mode), d1323 3 a1325 6 Provided all of the subsequent characters in the word are unquoted up to an unquoted slash (/) or when in an assignment or not in posix mode, an unquoted colon (:), or if neither of those appear, the end of the word, they are treated as a user name and are replaced with the pathname of the named user's home directory. a1330 5 .Pp In variable assignments, an unquoted tilde immediately after the assignment operator (=), and each unquoted tilde immediately after an unquoted colon in the value to be assigned is also subject to tilde expansion as just stated. @ 1.146.2.5 log @Pull up following revision(s) (requested by kre in ticket #323): bin/sh/sh.1: revision 1.168 Fix typo: s/one or mode/one or more/ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.146.2.4 2017/10/25 06:51:36 snj Exp $ d1898 1 a1898 1 but one or more names, @ 1.146.2.6 log @Pull up following revision(s) (requested by kre in ticket #1127): bin/sh/var.h: revision 1.38 (via patch) bin/sh/var.c: revision 1.72 bin/sh/sh.1: revision 1.211 (via patch) Alter a design botch when magic (self modifying) variables were added to sh ... in other shells, setting such a variable (for most of them) causes it to lose its special properties, and act the same as any other variable. I had assumed that was just implementor laziness... I was wrong. From now on the NetBSD shell will act like the others, and if vars like HOSTNAME (and SECONDS, etc) are used as variables in a script or whatever, they will act just like normal variables (and unless this happens when they have been made local, or as a variable-assignment as a prefix to a command, the special properties they would have had otherwise are lost for the remainder of the life of the (sub-)shell in which the variables were set). Importing a value from the environment counts as setting the value for this purpose (so if HOSTNAME is set in the environment, the value there will be the value $HOSTNAME expands to). The two exceptions to this are LINENO and RANDOM. RANDOM needs to be able to be set to (re-)set its seed. LINENO needs to be able to be set (at least in the "local" command) to achieve the desired functionality. It is unlikely that any (sane) script is going to want to use those two as normal vars however. While here, fix a minor bug in popping local vars (fn return) that need to notify the shell of changes in value (like PATH). Change sh(1) to reflect this alteration. Also add doc of the (forgotten) magic var EUSER (which has been there since the others were added), and add a few more vars (which are documented in other places in sh(1) - like ENV) into the defined or used variable list (as well as wherever else they appear). XXX pullup -8 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.211 2018/12/04 14:03:30 kre Exp $ a2317 15 If any of the shell's magic variables (those which return a value which may vary without the variable being explicitly altered, e.g.: .Dv SECONDS or .Dv HOSTNAME ) are made local in a function, they will lose their special properties when set within the function, including by the .Ic local command itself (if not to be set in the function, there is little point in making a variable local) but those properties will be restored when the function returns. a2987 24 .It Ev ENV Names the file sourced at startup by the shell. Unused by this shell after initialization, but is usually passed through the environment to descendant shells. .It Ev EUSER Set to the login name of the effective user id running the shell, as returned by .Bd -compact -literal -offset indent getpwuid(geteuid())->pw_name .Ed .Po See .Xr getpwuid 3 and .Xr geteuid 2 for more details. .Pc This is obtained each time .Ev EUSER is expanded, so changes to the shell's execution identity cause updates without further action. If unset, it returns nothing. If set it loses its special properties, and is simply a variable. d3006 2 a3007 1 If set it loses its special properties, and is simply a variable. a3058 16 .It Ev POSIXLY_CORRECT If set in the environment upon initialization of the shell, then the shell option .Ic posix will be set. .Po See the description of the .Ic set command in the .Sx Built-ins section. .Pc After initialization it is unused by the shell, but is usually passed through the environment to descendant processes, including other instances of the shell, which may interpret it in a similar way. d3150 1 a3151 1 If set, it loses its special properties, and becomes a normal variable. d3163 1 a3163 1 has not been set or unset. d3185 2 a3186 1 If set, it loses its special properties, and becomes a normal variable. @ 1.145 log @More standard (and saner) implementation of the ! reserved word. Unless the shell is compiled with the (compilation time) option BOGUS_NOT_COMMAND (as in CFLAGS+=-DBOGUS_NOT_COMMAND) which it will not normally be, the ! command (reserved word) will only be permitted at the start of a pipeline (which includes the degenerate pipeline with no '|'s in it of course - ie: a simple cmd) and not in the middle of a pipeline sequence (no "cmd | ! cmd" nonsense.) If the latter is really required, then "cmd | { ! cmd; }" works as a standard equivalent. In POSIX mode, permit only one ! ("! pipeline" is ok. "! ! pipeline" is not). Again, if needed (and POSIX conformance is wanted) "! { ! pipeline; }" works as an alternative - and is safer, some shells treat "! ! cmd" as being identical to "cmd" (this one did until recently.) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.144 2017/05/27 06:32:12 kre Exp $ d2105 1 a2105 1 the initial value and exported atribute @ 1.144 log @ It turns out that most shells do not do variable value/attribute inheritance when a variable is declared local, but instead leave the local var unset (if not given a value) in the function. Only ash derived shells do inheritance it seems. So, to compensate for that, and get one step closer to making "local" part of POSIX, so we can really rely upon it, a compromise has been suggested, where "local x" is implementation defined when it comes to this issue, and we add "local -I x" to specify inheritance, and "local -N x" to specify "not" (something...) (not inherited, or not set, or whatever you prefer to imagine!) The option names took a lot of hunting to find something reasonable that no shell (we know of) had already used for some other purpose... The I was easy, but 'u' 'U' 'X' ... all in use somewhere. This implements that (well, semi-) agreement. While here, add "local -x" (which many other shells already have) which causes the local variable to be made exported. Not a lot of gain in that (since "export x" can always be done immediately after "local x") but it is very cheap to add and allows more other scripts to work with out shell. Note that while 'local x="${x}"' always works to specify inheritance (while making the shell work harder), "local x; unset x" does not always work to specify the alternative, as some shells have "re-interpreted" unset of a local variable to mean something that would best be described as "unlocal" instead - ie: after the unset you might be back with the variable from the outer scope, rather than with an unset local variable. Also add "unset -x" to allow unsetting a variable without removing any exported status it has. There are gazillions of other options that are not supported here! @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.143 2017/05/18 13:56:58 kre Exp $ d388 3 a390 1 built-in command are passed on to utilities executed, d392 3 a394 3 an empty compound statement as a syntax error (required by posix) or permits it. Empty compound statements d397 3 @ 1.143 log @ Allow abbreviations of option names for the "fdflags -s" command. While documenting that, cleanup markup of the fdflags section of the man page. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.142 2017/05/18 13:53:18 kre Exp $ d1028 2 a1029 1 As an extension, this shell also allows a simple command to be d1065 1 a1065 1 Variables may be declared to be local to a function by using a d1069 5 a1073 1 its syntax is d1075 8 a1082 63 .Dl local [ variable | - ] ... .Pp .Dq Ic local is implemented as a built-in command. .Pp When a variable is made local, it inherits the initial value and exported, unexportable, and read-only flags from the variable with the same name in the surrounding scope, if there is one. Otherwise, the variable is initially unset. Making a read-only variable local is possible, but pointless. If the .Ic readonly command is applied to a variable that has been declared local, the variable cannot be (further) modified within the function, or any other functions it calls, however when the function returns, the previous status (and value) of the variable is returned. .Pp Values may be given to local variables on the .Ic local command line in a similar fashion as used for .Ic export and .Ic readonly . .Pp The shell uses dynamic scoping, so that if you make the variable x local to function f, which then calls function g, references to the variable x made inside g will refer to the variable x declared inside f, not to the global variable named x. .Pp Note that the parameters $1, $2, ... (see .Sx Positional Parameters ) , and $#, $* and $@@ (see .Sx Special Parameters ) , are always made local in all functions, and are reset inside the function to represent the options and arguments passed to the function. Note that $0 however retains the value it had outside the function, as do all the other special parameters. .Pp The only other special parameter that can be made local is .Dq - . Making .Dq - local causes any shell options that are changed via the set command inside the function to be restored to their original values when the function returns. .Pp It is a syntax error to use .Ic local outside the scope of a function definition. When used inside a function, it exits with status 0. .Pp The syntax of the return command is .Pp .Dl return [ exitstatus ] .Pp It terminates the currently executing function or .Dq \&. script. Return is implemented as a built-in command. The exit status of the function (or .Dl \&. command) is either that given on the d1084 5 a1088 3 command line, or the value of the special parameter .Dq $? immediately before the return was executed. d1588 1 d1608 5 a1612 1 The return command can be used for a premature return from the sourced file. d2083 135 d2300 1 a2300 1 .It return [ Ar n ] d2605 1 a2605 1 .It unset Oo Fl efv Oc Ar name ... d2615 5 a2619 1 is given, the specified variables are unexported, but otherwise unchanged. d2626 1 a2626 4 is given with one (or both) of .Fl v or .Fl e , d2629 2 a2630 2 It makes no sense to give both .Fl v d2632 4 d2637 4 a2640 2 as unsetting a variable unexports it as well. However doing so is not an error, the last specified is used. @ 1.142 log @ Command line, and "set" command options processing cleanup. sh +c "command string" no longer works (it must be -c) sh +o and sh -o no longer work (if you could call what they did before working.) nb: this is without an option name. -ooo Opt1 Opt2 Opt3 no longer works (set & cmd line), this should be -o Opt1 -o Opt2 -o Opt3 (same with +ooo of course). -oOpt is now supported - option value (name of option in this case) immediately following -o (or +o). (as with other commands that use std opt parsing) Both set comamnd and command line. In addition, the output from "set +o" has shrunk dramatically, by borrowing a trick from ksh93 (but implemented in a more traditional syntax). "set +o" is required to produce a command (or commands) which when executed later, will return all options to the state they were in when "set +o" was done. Previously that was done by generating a set command, with every option listed (set -o opt +o other-opt ...) to set them all back to their current setings. Now we have a new "magic option" ("default") which sets all options to their default values, so now set +o output need only be "set -o default -o changed-opt ..." (only the options that have been changed from their default values need be explicitly mentioned.) The definition of "default value" for this is the value the shell set the option to, after startup, after processing the command line (with any flags, or -o option type settings), but before beginning processing any user input (incuding startup files, like $ENV etc). Anyone can execute "set -o default" of course, but only from a "set" command (it makes no sense at all as a -o option to sh). This also causes "set +o" to be slightly more useful as a general command, as ignoring the "set -o default" part of the result, it lists just those options that have been altered after sh startup. There is no +o default. There isn't an option called "default" at all... This causes some of the commented out text from sh.1 to become uncommented. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.141 2017/05/14 17:27:05 kre Exp $ d1965 1 a1965 1 .Dq + d1967 1 a1967 1 .Dq - d1970 13 a1982 1 append,async,sync,nonblock,fsync,dsync,rsync,direct,nosigpipe,cloexec. d1985 2 @ 1.141 log @ When opening a file descritor with "exec n>/file" (and similar) only set the close-on-exec bit when not in posix mode (to comply with posix...) OK: christos@@ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.140 2017/05/14 14:14:39 kre Exp $ d215 2 a216 2 The following options can be set from the command line or with the d2234 17 a2250 17 .\" In addition to the options listed there, .\" when the .\" .Dq "option name" .\" given to .\" .Fl o .\" is .\" .Cm default .\" all of the options are reset to the values they had immediately .\" after .\" .Nm .\" initialization, before any startup scripts had been processed. .\" While this may be of use to users or scripts, its primary purpose .\" is for use in the output of .\" .Dq Ic set Cm +o , .\" to avoid that command needing to list every available option. .\" There is no .\" .Cm +o default . d2256 1 a2256 1 .Dq -- d2261 7 @ 1.140 log @ Add mention of ;& in the list of control operators (forgotten before). Document the (slightly) enhanced NETBSD_SHELL. Fix a typo (one of my typos...) Move a commented out section to align with current planned changes (and fix its commented out markup.) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.139 2017/05/14 10:53:26 wiz Exp $ d385 5 a389 1 It also controls whether the shell treats d1776 4 a1779 1 File descriptors created via such redirections are marked close-on-exec d1793 6 a1798 1 To turn off the close-on-exec mark, d1810 2 a1811 1 command below. @ 1.139 log @Use more, or more appropriate, markup. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.138 2017/05/12 08:55:38 kre Exp $ d297 13 a364 13 .\" .It "\ \ " Em lineno_fn_relative .\" When set, before a function is defined, .\" causes the variable .\" .Cm LINENO .\" when used within the function, .\" to refer to the line number defined such that .\" first line of the function is line 1. .\" When reset, .\" .Cm LINENO .\" in a function refers to the line number within the file .\" in which the definition of the function occurs .\" (which can be the number of lines of shell input from standard input .\" when a function is defined interactively from the command prompt.) d413 1 a413 1 .Dl \*[Am] \*[Am]\*[Am] \&( \&) \&; ;; | || \*[Lt]newline\*[Gt] d823 1 a823 1 could syntatically correctly be terminated at the point where d2686 9 a2694 1 It behaves like any other variable that has the read-only @ 1.138 log @ Improve the description of option processing (including the shell's arg list processing), and the set command in general. Also add some (new) commented out text related to options which may be commented back in sometime soon... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.137 2017/05/12 08:39:47 kre Exp $ d173 1 a173 1 .Dq case d175 1 a175 1 .Dq esac d452 4 a455 4 .It ! Ta { Ta } Ta case .It do Ta done Ta elif Ta else .It esac Ta fi Ta for Ta if .It in Ta then Ta until Ta while d543 1 a543 1 .It [n] Ns \*[Gt] file d545 2 a546 2 .Cm file . .It [n] Ns \*[Gt]| file d550 1 a550 1 .It [n] Ns \*[Gt]\*[Gt] file d552 12 a563 7 .Cm file . .It [n] Ns \*[Lt] file Redirect standard input (or n) from .Cm file . .It [n1] Ns \*[Lt]\*[Am] Ns n2 Duplicate standard input (or n1) from file descriptor n2. .Cm n2 d565 9 a573 5 .It [n] Ns \*[Lt]\*[Am]- Close standard input (or n). .It [n1] Ns \*[Gt]\*[Am] Ns n2 Duplicate standard output (or n1) to n2. .It [n] Ns \*[Gt]\*[Am]- d575 1 a575 1 .It [n] Ns \*[Lt]\*[Gt] file d577 3 a579 2 .Cm file for reading and writing on standard input (or n). d788 1 a788 1 .Cm wait d847 3 a849 1 The syntax of the if command is d860 1 a860 1 .Cm then d863 1 a863 1 .Cm elif d866 1 a866 1 .Cm elif d869 1 a869 1 .Cm else d872 3 a874 1 The syntax of the while command is d883 7 a889 3 The until command is similar, but has the word until in place of while, which causes it to repeat until the exit status of the first list is zero. d891 3 a893 1 The syntax of the for command is d903 5 a907 2 do and done may be replaced with .Dq { d909 1 a909 1 .Dq } , d912 5 a916 1 The syntax of the break and continue commands is d922 15 a936 2 Break terminates the num innermost for, while or until loops. Continue breaks execution of the num\-1 innermost for, while, or until d940 1 a940 1 .Cm num , d944 3 a946 1 The syntax of the case command is d975 4 a978 2 .Dv esac is reached execution of the case statement is complete. d1061 1 a1061 1 .Cm local d2329 1 a2329 1 .Ar -l d2337 1 a2337 1 .Ar -p a2370 1 .Pp d2385 1 a2385 1 untrapped (in their default states) d2628 3 a2630 2 The check occurs just before PS1 is written, immediately after reporting jobs which have changed status, d2735 5 a2739 1 PS1, PS2, and PS4 should be subject to parameter expansion before d2747 1 a2747 2 .\" markup? trap @ 1.137 log @ Corrected some typos, added some (hopefully improving) extra text, sorted stuff that needed sorting, and added some (probably incorrect) markup... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.136 2017/05/07 15:01:18 kre Exp $ d198 5 a202 2 All of the single letter options have a corresponding name that can be used as an argument to the d209 1 d219 1 a219 1 .Bl -tag -width aaaallexportfoo -offset indent d352 13 d2155 1 a2155 1 command performs three different functions. d2159 14 d2177 17 d2195 1 a2195 1 The third use of the set command is to set the values of the shell's d2201 1 a2201 1 If no arguments are present, the set command @ 1.136 log @ Enhance the trap command to make it possible to do what POSIX wants (even if no shell in existence, that I am aware of, does that). That is, POSIX says ... [of the trap command with no args] The shell shall format the output, including the proper use of quoting, so that it is suitable for re-input to the shell as commands that achieve the same trapping results. For example: save_traps=$(trap) ... eval "$save_traps" It is obvious what the intent is there. But no shell makes it work. An example using bash (as the NetBSD shell, still does not do the save_traps= stuff correctly - but that is a problem for a different time and place...) Given this script printf 'At start: '; trap printf '\n' traps=$(trap) trap 'echo hello' INT printf 'inside : '; trap printf '\n' eval "${traps}" printf 'At end : '; trap printf '\n' One would expect that (assuming no traps are set at the start, and there aren't) that the first trap will print nothing, then the inside trap will show the trap that was set, and then when we get to the end everything will be back to nothing again. But: At start: inside : trap -- 'echo hello' SIGINT At end : trap -- 'echo hello' SIGINT And of course. when you think about it, it is obvious why this happens. The first "trap" command prints nothing ... nothing has changed when we get to the "traps=$(trap)" command ... that trap command also prints nothing. So this does traps=''. When we do eval "${traps}" we are doing eval "", and it is hardly surprising that this accomplishes nothing! Now we cannot rationally change the "trap" command without args to behave in a way that would make it useful for the posix purpose (and here, what they're aiming for is good, it should be possible to accomplish that objective) so is there some other way? I think I have seen some shell (but I do not remember which one) that actually has "trap -" that resets all traps to the default, so with that, if we changed the 'eval "${traps}"' line to 'trap -; eval "${traps}"' then things would actually work - kind of - that version has race conditions, so is not really safe to use (it will work, most of the time...) But, both ksh93 and bash have a -p arg to "trap" that allows information about the current trap status of named signals to be reported. Unfortunately they don't do quite the same thing, but that's not important right now, either would be usable, and they are, but it is a lot of effort, not nearly as simple as the posix example. First, while "trap -p" (with no signals specified) works, it works just the same (in both bash and ksh93, aside from output format) as "trap". That is, that is useless. But we can to trap_int=$(trap -p int) trap_hup=$(trap -p hup) ... and then reset them all, one by one, later... (bash syntax) test -n "${trap_int}" && eval "${trap_int}" || trap - int test -n "${trap_hup}" && eval "${trap_hup}" || trap - hup (ksh93 syntax) trap "${trap_int:-}" int trap "${trap_hup:-}" hup the test (for bash) and variable with default for ksh93, is needed because they both still print nothing if the signal action is the default. So, this modification attempts to fix all of that... 1) we add trap -p, but make it always output something for every signal listed (all of the signals if none are given) even if the signal action is the default. 2) choose the bash output format for trap -p, over the ksh93 format, even though the simpler usage just above makes the ksh93 form seem better. But it isn't. Consider: ksh93$ trap -p int hup echo hello One of the two traps has "echo hello" as its action, the other is still at the default, but which? From bash... bash$ trap -p int hup trap -- 'echo hello' SIGINT And now we know! Given the bash 'trap -p' format, the following function produces ksh93 format output (for use with named signals only) instead... ksh93_trap_p() { for _ARG_ do _TRAP_=$(trap -p "${_ARG_}") || return 1 eval set -- "${_TRAP_}" printf '%s' "$3${3:+ }" done return 0 } [ It needs to be entered without the indentation, that '}"' line has to be at the margin. If the shell running that has local vars (bash does) then _ARG_ and _TRAP_ should be made local. ] So the bash format was chosen (except we do not include the "SIG" on the signal names. That's irrelevant.) If no traps are set, "trap -p" will say (on NetBSD of course)... trap -- - EXIT HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS trap -- - PIPE ALRM TERM URG STOP TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ trap -- - VTALRM PROF WINCH INFO USR1 USR2 PWR RT0 RT1 RT2 RT3 RT4 RT5 trap -- - RT6 RT7 RT8 RT9 RT10 RT11 RT12 RT13 RT14 RT15 RT16 RT17 RT18 trap -- - RT19 RT20 RT21 RT22 RT23 RT24 RT25 RT26 RT27 RT28 RT29 RT30 Obviously if traps are set, the relevant signal names will be removed from that list, and additional lines added for the trapped signals. With args, the signals names are listed, one line each, whatever the status of the trap for that signal is: $ trap -p HUP INT QUIT trap -- - HUP trap -- 'echo interrupted' INT trap -- - QUIT 3) we add "trap -" to reset all traps to default. (It is easy, and seems useful.) 4) While here, lots of generic cleanup. In particular, get rid of the NSIG+1 nonsense, and anything that ever believes a signo == NSIG is in any way rational. Before there was a bunch of confusion, as we need all the signals for traps, plus one more for the EXIT trap, which looks like we then need NSIG+1. But EXIT is 0, NSIG includes signals from 0..NSIG-1 but there is no signal 0, EXIT uses that slot, so we do not need to add and extra one, NSIG is enough. (To see the effect of this, use a /bin/sh from before this fix, and compare the output from trap '' 64 and trap '' 65 both invalid signal numbers. Then try just "trap" and watch your shell drop core...) Eventually NSIG needs to go away completely (from user apps), it is not POSIX, it isn't really useful (unless we make lots of assumptions about how signals are numbered, which are not guaranteed, so even if apps, like this sh, work on NetBSD, they're not portable,) and it isn't necessary (or will not be, soon.) But that is for another day... 5) As is kind of obvious above, when listing "all" traps, list all the ones still at their defaults, and all the ignored signals, on as few lines as possible (it could all be on one line - technically it would work as well, but it would have made this cvs log message really ugly...) Signals with a non-null action still get listed one to a line (even if several do have the exact same action.) 6) Man page updates as well. After this change, the following script: printf 'At start: '; trap printf '\n' trap -p >/tmp/out.$$ trap 'echo hello' INT printf 'inside : '; trap printf '\n' . /tmp/out.$$; rm /tmp/out.$$ printf 'At end : '; trap printf '\n' which is just the example from above, using "trap -p" instead of just "trap" to save the traps, and modified to a form that will work with the NetBSD shell today produces: At start: inside : trap -- 'echo hello' INT At end : [Do I get a prize for longest commit log message of the year?] @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.135 2017/05/04 04:37:51 kre Exp $ d34 1 a34 1 .Dd May 7, 2017 a92 6 Only features designated by .Tn POSIX , plus a few Berkeley extensions, are being incorporated into this shell. .\" We expect .\" .Tn POSIX .\" conformance by the time 4.4 BSD is released. d113 3 a115 2 If no arguments are present and if the standard input of the shell is connected to a terminal (or if the d138 2 a139 1 is set on entry to a shell, or is set in the d141 5 a145 1 of a login shell, the shell next reads d167 1 a167 1 file is read for every invocation of the shell, including shell scripts d218 3 a258 49 .It Fl f Em noglob Disable pathname expansion. .It Fl n Em noexec If not interactive, read commands but do not execute them. This is useful for checking the syntax of shell scripts. .It Fl u Em nounset Write a message to standard error when attempting to expand a variable that is not set, and if the shell is not interactive, exit immediately. .It Fl v Em verbose The shell writes its input to standard error as it is read. Useful for debugging. .It Fl x Em xtrace Write each command to standard error (preceded by a .Sq +\ ) before it is executed. Useful for debugging. .It Fl q Em quietprofile If the .Fl v or .Fl x options have been set, do not apply them when reading initialization files, these being .Pa /etc/profile , .Pa .profile , and the file specified by the .Ev ENV environment variable. .It Fl I Em ignoreeof Ignore EOFs from input when interactive. .It Fl i Em interactive Force the shell to behave interactively. .It Fl m Em monitor Turn on job control (set automatically when interactive). .It Fl s Em stdin Read commands from standard input (set automatically if no file arguments are present). This option has no effect when set or reset after the shell has already started running (i.e. with .Ic set ) . .It Fl V Em vi Enable the built-in .Xr vi 1 command line editor (disables .Fl E if it has been set). (See the .Sx Command Line Editing section below.) d267 2 a268 3 .It Fl b Em notify Enable asynchronous notification of background job completion. (Not implemented.) d289 9 d305 38 d368 6 a373 3 Consequently, while it can be manipulated by the .Ic set command, doing so has no current purpose. d393 1 a393 1 Following is a list of operators: d406 1 a406 1 A backslash preserves the literal meaning of the following d409 1 a409 1 A backslash preceding a d411 1 a411 1 is treated as a line continuation. d425 3 a427 2 quote only the following characters: .Dl $ ` \*q \e \*[Lt]newline\*[Gt] . d434 5 a438 4 .Bl -column while while while while while -offset indent .It ! Ta elif Ta fi Ta while Ta case .It else Ta for Ta then Ta { Ta } .It do Ta done Ta until Ta if Ta esac d441 1 a441 1 Their meaning is discussed later. d446 1 a446 1 Whenever a reserved word may occur (see above), d465 1 a465 1 This use is discouraged. d484 2 a485 1 are stripped off and assigned to the environment of the simple command. d487 1 a487 1 stripped off and saved for processing. d491 2 a492 2 section below, and the first remaining word is considered the command name and the d494 1 a494 1 The remaining words are considered the arguments of the command. d499 2 a500 1 Redirections are performed as described in the next section. d514 1 a514 1 Following is a list of the possible redirections. d522 3 d527 2 a528 1 Redirect standard output (or n) to file. d530 1 a530 1 Same, but override the d534 2 a535 1 Append standard output (or n) to file. d537 2 a538 1 Redirect standard input (or n) from file. d541 2 d550 3 a552 1 Open file for reading and writing on standard input (or n). d564 10 d581 5 a585 1 subjected to parameter expansion, command substitution, and arithmetic d599 3 d605 3 d615 2 a616 1 made local to the function and are set to the values given. d618 4 a621 3 The positional parameters are restored to their original values when the command completes. This all occurs within the current shell. d631 1 a631 1 If the program is not a normal executable file (i.e., if it does d638 1 a638 1 then) the shell will interpret the program in a subshell. d658 1 a658 1 The shell searches each entry in d667 3 d675 2 a676 1 with zero for normal or success, and non-zero for failure, d686 4 d711 5 a715 1 by the control operator |. d730 1 a730 1 by redirection operators that are part of the command. d757 6 d786 1 a786 1 A list is a sequence of zero or more commands separated by newlines, d793 5 d829 13 d872 1 a872 1 The syntax of the break and continue command is d878 3 a880 2 Break terminates the num innermost for or while loops. Continue continues with the next iteration of the innermost loop. d882 4 d929 7 a935 1 The first of these executes the commands in a subshell. d937 2 a938 1 The second form does not fork another shell so is slightly more efficient. d962 1 a962 1 compound commands, or a sub-shell, all of which are supported. d999 2 a1000 1 Variables may be declared to be local to a function by using a local d1002 2 a1003 1 This should appear as the first statement of a function, and the syntax is d1044 1 a1044 1 The only special parameter that can be made local is d1076 1 a1076 1 variables into shell variables. d1148 1 a1148 1 .It - (Hyphen.) d1155 1 a1155 1 A subshell retains the same value of $ as its parent. d1205 4 a1208 4 All the characters up to a slash (/) or the end of the word are treated as a username and are replaced with the user's home directory. If the username is missing (as in d1233 3 a1235 2 The parameter name or symbol can be enclosed in braces, which are optional except for positional parameters with more than one digit or d1247 2 a1248 2 In addition, a parameter expansion can be modified by using one of the following formats. d1251 2 a1252 2 is omitted in the following modifiers, then the expansion is applied only to unset parameters, not null ones. d1269 5 a1273 3 is written to standard error and the shell exits with a nonzero exit status. Otherwise, the value of parameter is substituted. An interactive shell need not exit. d1278 1 d1299 3 d1307 6 d1318 3 d1326 6 d1335 1 a1335 1 place of the command name itself. d1349 1 a1349 1 subshell environment and replacing the command substitution with the d1361 1 a1361 1 and quoting that is in effect.) d1460 1 a1460 1 whitespace, and d1469 1 a1469 1 delimiter acts as a field separator. d1556 11 a1566 1 make it the first or last character listed. d1735 3 d1743 1 a1743 1 exit status of the preceding command is used. d1747 1 d1876 2 d1992 1 a1992 1 shift $(expr $OPTIND - 1) d2057 1 a2057 1 command doesn't currently support the d2062 1 a2062 1 is changed, d2084 1 a2084 1 line and the line is split as described in the d2107 1 a2107 1 .It readonly Fl p d2224 1 a2224 1 When the shell forks off a subshell, it resets trapped (but not ignored) d2334 2 a2335 4 .It Fl t show or set the limit on CPU time (in seconds) .It Fl f show or set the limit on the largest file that can be created d2339 2 a2340 4 .It Fl s show or set the limit on the stack size of a process (in kilobytes) .It Fl c show or set the limit on the largest core dump size that can be produced a2341 3 .It Fl m show or set the limit on the total physical memory that can be in use by a process (in kilobytes) d2346 8 d2357 4 a2360 5 .It Fl p show or set the limit on the number of processes this user can have at one time .It Fl n show or set the limit on the number of files a process can have open at once d2373 1 a2373 1 .It umask Op Ar mask d2378 3 d2531 2 d2563 5 d2586 1 a2586 1 Unlike the variables mentioned above, d2591 1 a2591 1 If set, it indicates that the shell is the d2656 1 a2656 1 subshell environment, d2658 1 a2658 1 As a workaround, it is possible to redirect ooutput from @ 1.135 log @ Implement the ';&' (used instead of ';;') case statement list terminator which causes fall through the to command list of the following pattern (wuthout evaluating that pattern). This has been approved for inclusion in the next major version of the POSIX standard (Issue 8), and is implemented by most other shells. Now all form a circle and together attempt to summon the great wizd in the hopes that his magic spells can transform the poor attempt at documenting this feature into something rational... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.134 2017/05/03 00:43:22 kre Exp $ d34 1 a34 1 .Dd May 4, 2017 d2059 2 d2062 1 a2062 1 .It trap Ar action signal ... d2064 1 d2074 1 d2076 2 a2077 1 may be null, which cause the specified signals to be ignored. d2082 1 a2082 1 the specified signals are set to their default action. d2093 3 d2106 1 d2113 9 a2121 3 without any arguments cause it to write a list of signals and their associated action to the standard output in a format that is suitable as an input to the shell that achieves the same trapping results. d2127 1 a2127 1 List trapped signals and their corresponding action. d2147 1 a2147 1 command upon receiving signal INT. d2152 19 d2498 4 a2501 1 It was, however, unmaintainable so we wrote this one. d2513 16 d2530 1 @ 1.134 log @ Undocument (comment out) the description of the unimplemented MAILCHECK variable, and while here, enhance the description of MAIL a little. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.133 2017/04/30 16:02:48 wiz Exp $ d34 1 a34 1 .Dd April 29, 2017 d810 2 a811 1 pattern) list ;; d821 19 @ 1.133 log @Uppercase UID. Fix typo. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.132 2017/04/29 15:26:44 kre Exp $ d2351 13 a2363 8 .It Ev MAILCHECK The frequency in seconds that the shell checks for the arrival of mail in the files specified by the .Ev MAILPATH or the .Ev MAIL file. If set to 0, the check will occur at each prompt. @ 1.132 log @ Correct description of the trap command (make it posix compatible) and add a couple more examples. Also terminate a few sentences... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.131 2017/04/14 08:48:01 abhinav Exp $ d337 1 a337 1 Do not attempt to reset effective uid if it does not match uid. d2062 1 a2062 1 can be ommitted to achieve the same effect. @ 1.131 log @Fix mandoc -Tlint warnings: s/PP/Pp Remove Pp before It @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.130 2017/04/14 08:40:30 abhinav Exp $ d34 1 a34 1 .Dd March 20, 2017 d2040 2 a2041 1 .It trap Oo Ar action Oc Ar signal ... d2055 1 a2055 1 omitted or set to d2058 11 d2092 1 a2092 1 List trapped signals and their corresponding action d2096 1 a2096 1 Print a list of valid signals d2100 1 a2100 1 Ignore signals INT QUIT TSTP USR1 d2106 11 a2116 1 command (print the date) upon receiving signal INT @ 1.131.2.1 log @Sync with HEAD - tag prg-localcount2-base1 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.133 2017/04/30 16:02:48 wiz Exp $ d34 1 a34 1 .Dd April 29, 2017 d337 1 a337 1 Do not attempt to reset effective UID if it does not match UID. d2040 1 a2040 2 .It trap Ar action signal ... .It trap Ar N signal ... d2054 1 a2054 1 set to a2056 11 If the first .Ar signal is specified in its numeric form, then .Ar action can be omitted to achieve the same effect. This archaic, but still standard, form should not be relied upon, use the explicit .Sq - action. .Pp d2080 1 a2080 1 List trapped signals and their corresponding action. d2084 1 a2084 1 Print a list of valid signals. d2088 1 a2088 1 Ignore signals INT QUIT TSTP USR1. d2094 1 a2094 11 command (print the date) upon receiving signal INT. .Pp .Dl trap HUP INT .Pp Run the .Dq HUP command upon receiving signal INT. .Pp .Dl trap 1 2 .Pp Reset the actions for signals 1 (HUP) and 2 (INT) to their defaults. @ 1.131.2.2 log @Sync with HEAD @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.136 2017/05/07 15:01:18 kre Exp $ d34 1 a34 1 .Dd May 7, 2017 d810 1 a810 2 [(] pattern ) list ;& [(] pattern ) list ;; a819 19 .Pp Word is expanded and matched against each pattern in turn, from first to last, with each pattern being expanded just before the match is attempted. When a match is found, pattern comparisons cease, and the associated .Dq list (which may be empty) is evaluated. If the list is terminated with .Dq \&;& execution then falls through to the following list, if any, without evaluating its pattern, or attempting a match. When a list terminated with .Dq \&;; has been executed, or when .Dv esac is reached execution of the case statement is complete. The exit status is that of the last command executed from the last list evaluated, if any, or zero otherwise. d2039 1 a2040 3 .It trap \- .It trap Oo Fl l Oc .It trap Oo Fl p Oc signal ... a2041 1 .Pp a2050 1 The d2052 1 a2052 2 may be a null (empty) string, which causes the specified signals to be ignored. d2057 1 a2057 1 the specified signals are set to their default actions. a2067 3 If no signals are specified with an action of .Sq - , all signals are reset. a2077 1 .Pp d2084 3 a2086 9 without any arguments causes it to write a list of signals and their associated non-default actions to the standard output in a format that is suitable as an input to the shell that achieves the same trapping results. With the .Ar -p flag, trap prints the same information for the signals specified, or if none are given, for all signals, including those where the action is the default. d2092 1 a2092 1 List trapped signals and their corresponding actions. d2112 1 a2112 1 command, or function, upon receiving signal INT. a2116 19 .Pp .Bd -literal -offset indent traps=$(trap -p) # more commands ... trap 'action' SIG # more commands ... eval "$traps" .Ed .Pp Save the trap status, execute commands, changing some traps, and then reset all traps to their values at the start of the sequence. The .Fl p option is required in the first command here, or any signals that were previously untrapped (in their default states) and which were altered during the intermediate code, would not be reset by the final .Dq eval . d2351 8 a2358 13 The check occurs just before PS1 is written, immediately after reporting jobs which have changed status, in interactive shells only. New mail is considered to have arrived if the monitored file has increased in size since the last check. .\" .It Ev MAILCHECK .\" The frequency in seconds that the shell checks for the arrival of mail .\" in the files specified by the .\" .Ev MAILPATH .\" or the .\" .Ev MAIL .\" file. .\" If set to 0, the check will occur at each prompt. d2439 1 a2439 4 It was replaced in .At v7 with a version that introduced the basis of the current syntax. That was, however, unmaintainable so we wrote this one. a2450 16 The .\" markup? trap command cannot usefully be used, yet, within a command substitution, to obtain the current trap values, as all command substitutions are currently executed within a subshell environment, and in sub-shells all non-ignored, non-default, traps are reset. As a workaround, it is possible to redirect ooutput from .Dq trap or .Dq trap -p to a file, and then read the file later using the .Dq \&. command. .Pp a2451 1 (But less than there were...) @ 1.131.2.3 log @Resolve conflicts from previous merge (all resulting from $NetBSD keywork expansion) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.143 2017/05/18 13:56:58 kre Exp $ d34 1 a34 1 .Dd May 12, 2017 d93 6 d119 2 a120 3 If no arguments are present and if the standard input, and output, of the shell are connected to a terminal (or if the d143 1 a143 2 is set on entry to a shell, or is set in the d145 1 a145 5 of a login shell, and either the shell is interactive, or the .Cm posix option is not set, the shell next reads d167 1 a167 1 file can be read for every invocation of the shell, including shell scripts d173 1 a173 1 .Dq Ic case d175 1 a175 1 .Dq Ic esac d198 2 a199 5 Currently, all of the single letter options that can meaningfully be set using the .Ic set built-in, have a corresponding name that can be used as an argument to the a205 1 Other options described are for the command line only. d211 2 a212 2 The following options can be set from the command line and, unless otherwise stated, with the d215 1 a215 1 .Bl -tag -width \-WXXlineno_fn_relativeXX -offset indent a217 3 .It Fl b Em notify Enable asynchronous notification of background job completion. (Not implemented.) d256 49 d313 3 a315 2 .It Fl f Em noglob Disable pathname expansion. a335 22 .It Fl i Em interactive Force the shell to behave interactively. .It Fl I Em ignoreeof Ignore EOFs from input when interactive. .\" .It Fl L Em lineno_fn_relative .\" When set, before a function is defined, .\" causes the variable .\" .Ev LINENO .\" when used within the function, .\" to refer to the line number defined such that .\" first line of the function is line 1. .\" When reset, .\" .Ev LINENO .\" in a function refers to the line number within the file .\" in which the definition of the function occurs .\" (which can be the number of lines of shell input from standard input .\" when a function is defined interactively from the command prompt.) .It Fl m Em monitor Turn on job control (set automatically when interactive). .It Fl n Em noexec If not interactive, read commands but do not execute them. This is useful for checking the syntax of shell scripts. a342 38 .It Fl q Em quietprofile If the .Fl v or .Fl x options have been set, do not apply them when reading initialization files, these being .Pa /etc/profile , .Pa .profile , and the file specified by the .Ev ENV environment variable. .It Fl s Em stdin Read commands from standard input (set automatically if no file arguments are present). This option has no effect when set or reset after the shell has already started running (i.e. with .Ic set ) . .It Fl u Em nounset Write a message to standard error when attempting to expand a variable that is not set, and if the shell is not interactive, exit immediately. .It Fl v Em verbose The shell writes its input to standard error as it is read. Useful for debugging. .It Fl x Em xtrace Write each command to standard error (preceded by a .Sq +\ ) before it is executed. Useful for debugging. .It Fl V Em vi Enable the built-in .Xr vi 1 command line editor (disables .Fl E if it has been set). (See the .Sx Command Line Editing section below.) d368 3 a370 10 It also controls whether file descriptors greater than 2 opened using the .Ic exec built-in command are passed on to utilities executed, and whether the shell treats an empty compound statement as a syntax error (required by posix) or permits it. Empty compound statements .Dq "{ }" can be useful when defining dummy functions. d390 1 a390 1 The following is a list of operators: d393 1 a393 1 .Dl \*[Am] \*[Am]\*[Am] \&( \&) \&; ;; ;\*[Am] | || \*[Lt]newline\*[Gt] d403 1 a403 1 An unquoted backslash preserves the literal meaning of the following d406 1 a406 1 An unquoted backslash preceding a d408 1 a408 1 is treated as a line continuation, the two characters are simply removed. d422 2 a423 3 quote only the following characters (and these not in all contexts): .Dl $ ` \*q \e \*[Lt]newline\*[Gt] , where a backslash newline is a line continuation as above. d430 4 a433 5 .Bl -column while while while while -offset indent .It Ic \&! Ta Ic \&{ Ta Ic \&} Ta Ic case .It Ic do Ta Ic done Ta Ic elif Ta Ic else .It Ic esac Ta Ic fi Ta Ic for Ta Ic if .It Ic in Ta Ic then Ta Ic until Ta Ic while d436 1 a436 1 Their meanings are discussed later. d441 1 a441 1 Whenever a reserved word (see above) may occur, d460 1 a460 1 This use is strongly discouraged. d479 1 a479 2 are stripped off, the value is expanded, as described below, and the results are assigned to the environment of the simple command. d481 1 a481 1 stripped off and saved for processing in step 3 below. d485 2 a486 2 section below. The first remaining word is considered the command name and the d488 1 a488 1 Any remaining words are considered the arguments of the command. d493 1 a493 2 Redirections are performed, from first to last, in the order given, as described in the next section. d507 1 a507 1 The following is a list of the possible redirections. a514 3 If present it must occur immediately before the redirection operator, with no intervening white space, and becomes a part of that operator. d516 4 a519 5 .It Oo Ar n Oc Ns \*[Gt] Ar file Redirect standard output (or n) to .Ar file . .It Oo Ar n Oc Ns \*[Gt]| file The same, but override the d522 11 a532 24 .It Oo Ar n Oc Ns \*[Gt]\*[Gt] Ar file Append standard output (or n) to .Ar file . .It Oo Ar n Oc Ns \*[Lt] Ar file Redirect standard input (or .Ar n ) from .Ar file . .It Oo Ar n1 Oc Ns \*[Lt]\*[Am] Ns Ar n2 Duplicate standard input (or .Ar n1 ) from file descriptor .Ar n2 . .Ar n2 is expanded if not a digit string, the result must be a number. .It Oo Ar n Oc Ns \*[Lt]\*[Am]- Close standard input (or .Ar n ) . .It Oo Ar n1 Oc Ns \*[Gt]\*[Am] Ns Ar n2 Duplicate standard output (or .Ar n1 ) to .Ar n2 . .It Oo Ar n Oc Ns \*[Gt]\*[Am]- d534 2 a535 5 .It Oo Ar n Oc Ns \*[Lt]\*[Gt] Ar file Open .Ar file for reading and writing on standard input (or .Ar n ) . a546 10 The .Dq here-doc-text starts immediately after the next unquoted newline character following the here-doc redirection operator. If there is more than one here-document redirection on the same line, then the text for the first (from left to right) is read first, and subsequent here-doc-text for later here-doc redirections follows immediately after, until all such redirections have been processed. .Pp d554 1 a554 5 treated much like a double quoted string, except that .Sq \&" characters have no special meaning, and are not escaped by .Sq \&\e , and is subjected to parameter expansion, command substitution, and arithmetic a567 3 .Pp It is a syntax error for the end of the input file (or string) to be reached before the delimiter is encountered. a570 3 A command that contains a slash .Sq \&/ in its name is always a normal program. d578 1 a578 2 made local to the function and are set to the values given, and exported for the benefit of programs executed with the function. d580 3 a582 4 The positional parameters, and local variables, are restored to their original values when the command completes. This all occurs within the current shell, and the function can alter variables, or other settings, of the shell. d592 1 a592 1 If the program is not a normal executable file, and if it does d599 1 a599 1 then) the shell will interpret the program in a sub-shell. d619 1 a619 1 Otherwise, the shell searches each entry in a627 3 If a directory searched contains an executable file with the same name as the command given, the search terminates, and that program is executed. d633 1 a633 2 with zero in normal cases, or to indicate success, and non-zero for failure, a642 4 .Pp If redirections are present, and any fail to be correctly performed, any command present is not executed, and an exit status of 2 is returned. d664 1 a664 5 by the control operator .Sq \&| , and optionally preceded by the .Dq \&! reserved word. d679 1 a679 1 by redirection operators that are part of the command are performed. a705 6 The exit status of an asynchronous AND-OR-list is zero. The actual status of the commands, after they have completed, can be obtained using the .Ic wait built-in command described later. d729 1 a729 1 A list is a sequence of one or more commands separated by newlines, a735 5 A newline is equivalent to a .Sq \&; when no other operator is present, and the command being input could syntactically correctly be terminated at the point where the newline is encountered, otherwise it is just whitespace. d758 1 a758 3 The syntax of the .Ic if command is d767 2 a768 17 The first list is executed, and if the exit status of that list is zero, the list following the .Ic then is executed. Otherwise the list after an .Ic elif (if any) is executed and the process repeats. When no more .Ic elif reserved words, and accompanying lists, appear, the list after the .Ic else reserved word, if any, is executed. .Pp The syntax of the .Ic while command is d777 3 a779 7 The .Ic until command is similar, but has the word .Ic until in place of .Ic while , which causes it to repeat until the exit status of the first list is zero. d781 1 a781 3 The syntax of the .Ic for command is d791 2 a792 5 .Ic do and .Ic done may be replaced with .Sq Ic \&{ d794 1 a794 1 .Sq Ic \&} , d797 1 a797 5 The syntax of the .Ic break and .Ic continue commands is d803 2 a804 16 .Ic break terminates the .Ar num innermost .Ic for , while , or .Ic until loops. .Ic continue breaks execution of the .Ar num\-1 innermost .Ic for , while , or .Ic until loops, and then continues with the next iteration of the enclosing loop. a805 4 The parameter .Ar num , if given, must be an unsigned positive integer (greater than zero). If not given, 1 is used. d807 1 a807 3 The syntax of the .Ic case command is d836 2 a837 4 .Ic esac is reached execution of the .Ic case statement is complete. d849 1 a849 7 Note that while parentheses are operators, and do not require any extra syntax, braces are reserved words, so the opening brace must be followed by white space (or some other operator), and the closing brace must occur in a position where a new command word might otherwise appear. .Pp The first of these executes the commands in a sub-shell. d851 1 a851 2 The second form does not fork another shell so is slightly more efficient, and allows for commands which do affect the current shell. d875 1 a875 1 compound commands, including a sub-shell, all of which are supported. d912 1 a912 2 Variables may be declared to be local to a function by using a .Ic local d914 1 a914 2 This should usually appear as the first statement of a function, its syntax is d955 1 a955 1 The only other special parameter that can be made local is d987 1 a987 1 variables into shell variables, and exports them. d1059 1 a1059 1 .It \- (Hyphen, or minus.) d1066 1 a1066 1 A sub-shell retains the same value of $ as its parent. d1116 4 a1119 4 All the following characters in the word up to a slash (/) or the end of the word are treated as a user name and are replaced with the named user's home directory. If the user name is missing (as in d1144 2 a1145 3 The parameter name or symbol can be enclosed in braces, which are optional in this simple case, except for positional parameters with more than one digit or d1157 2 a1158 2 In addition, a parameter expansion where braces are used, can be modified by using one of the following formats. d1161 2 a1162 2 is omitted in the following modifiers, then the test in the expansion applies only to unset parameters, not null ones. d1179 3 a1181 5 is written to standard error and a non-interactive shell exits with a nonzero exit status. An interactive shell will not exit, but any associated command(s) will not be executed. If the parameter is set, its value is substituted. a1185 1 The value of parameter is not used in this expansion. a1205 3 If the word is to start with a .Sq \&% character, it must be quoted. a1210 6 The .Dq %% pattern operator only produces different results from the .Dq \&% operator when the pattern contains at least one unquoted .Sq \&* . a1215 3 If the word is to start with a .Sq \&# character, it must be quoted. a1220 6 This has the same relationship with the .Sq \&# pattern operator as .Dq %% has with .Dq \&% . d1224 1 a1224 1 place of the command (and surrounding syntax). d1238 1 a1238 1 sub-shell environment and replacing the command substitution with the d1250 1 a1250 1 and any quoting that is in effect.) d1349 1 a1349 1 whitespace, and any d1358 1 a1358 1 delimiter acts as a single field separator. d1445 1 a1445 11 make it the first (after !) or last character listed. If both .Dq \&] and .Dq \(mi are to be included, the .Dq \&] must be first (after !) and the .Dq \(mi last, in the character class. d1590 1 a1590 4 When the .Ic posix option is not set, file descriptors created via such redirections are marked close-on-exec d1604 1 a1604 6 This behavior is required by the .Tn POSIX standard, so when the .Ic posix option is set, this shell also acts that way. To be assured the close-on-exec setting is off, a1613 4 Alternatively, see the .Ic fdflags command below, which can set, or clear, this, and other, file descriptor flags. d1619 1 a1619 1 exit status of the preceding command (the current value of $?) is used. a1622 1 but one or mode names, a1750 2 A foreground job can interact with the user via standard input, and receive signals from the terminal. d1764 1 a1764 1 .Dq \(pl d1766 1 a1766 1 .Dq \(mi d1769 1 a1769 13 .Cm append , .Cm async , .Cm sync , .Cm nonblock , .Cm fsync , .Cm dsync , .Cm rsync , .Cm direct , .Cm nosigpipe , and .Cm cloexec . Unique abbreviations of these names, of at least 2 characters, may be used on input. a1771 2 and .Xr open 2 d1865 1 a1865 1 shift $((OPTIND - 1)) d1930 1 a1930 1 command doesn't support the d1935 1 a1935 1 is changed (as unlikely as that is), d1957 1 a1957 1 line and the line is split as described in the field splitting section of the d1980 1 a1980 1 .It readonly Oo Fl p Oc d2011 1 a2011 1 command performs four different functions. a2014 14 With a single option of either .Sq Fl o or .Sq Cm +o .Ic set outputs the current values of the options. In the .Fl o form, all options are listed, with their current values. In the .Cm +o form, the shell outputs a string that can later be used as a command to reset all options to their current values. .Pp a2018 17 In addition to the options listed there, when the .Dq "option name" given to .Ic set Fl o is .Cm default all of the options are reset to the values they had immediately after .Nm initialization, before any startup scripts, or other input, had been processed. While this may be of use to users or scripts, its primary purpose is for use in the output of .Dq Ic set Cm +o , to avoid that command needing to list every available option. There is no .Cm +o default . d2020 1 a2020 1 The fourth use of the set command is to set the values of the shell's d2024 1 a2024 1 .Dq -\|- d2026 1 a2026 1 If no following arguments are present, the set command a2028 7 Otherwise the following arguments become .Do \&$1 Dc Ns \&, .Do \&$2 Dc Ns \&, \&..., and .Dq \&$# is set to the number of arguments present. d2097 1 a2097 1 When the shell forks off a sub-shell, it resets trapped (but not ignored) d2110 1 a2110 1 .Fl l d2118 1 a2118 1 .Fl p d2152 1 d2167 1 a2167 1 untrapped (in their default states) d2207 4 a2210 2 .It Fl c show or set the limit on the largest core dump size that can be produced d2214 4 a2217 2 .It Fl f show or set the limit on the largest file that can be created d2219 3 d2226 3 a2228 5 .It Fl m show or set the limit on the total physical memory that can be in use by a process (in kilobytes) .It Fl n show or set the limit on the number of files a process can have open at once d2232 2 a2233 7 .It Fl r show or set the limit on the number of threads this user can have at one time .It Fl s show or set the limit on the stack size of a process (in kilobytes) .It Fl t show or set the limit on CPU time (in seconds) d2246 1 a2246 1 .It umask Oo Fl S Oc Op Ar mask a2250 3 With .Fl S a symbolic form is used instead of an octal number. a2400 2 The value of this variable is automatically set by the shell, even if made readonly. d2405 2 a2406 3 The check occurs just before .Ev PS1 is written, immediately after reporting jobs which have changed status, a2430 5 .It Ev PPID The process identified of the parent process of the current shell. This value is set at shell startup, ignoring any value in the environment, and then made readonly. d2449 1 a2449 1 Unlike the variables previously mentioned, d2454 1 a2454 1 If set, by the shell, it indicates that the shell is the d2457 1 a2457 9 It can also give information in additional space separated words, after the version string. If the shell was built as part of a reproducible build, the relevant date that was used for that build will be included. Finally, any non-standard compilation options, which may affect features available, that were used when building the shell will be listed. .Ev NETBSD_SHELL behaves like any other variable that has the read-only d2506 1 a2506 5 .Ev PS1 , .Ev PS2 , and .Ev PS4 should be subject to parameter expansion before d2514 2 a2515 1 .Ic trap d2519 1 a2519 1 sub-shell environment, d2521 1 a2521 1 As a workaround, it is possible to redirect output from @ 1.130 log @Instead of removing markup as I did in the last commit, use markup but properly. Hint taken from FreeBSD man page. ok wiz@@ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.129 2017/04/03 14:08:37 abhinav Exp $ d1289 1 a1289 1 .PP a1972 1 .Pp a2169 1 .Pp @ 1.129 log @Use \- instead of .Fl for the -number argument. .Fl causes the -number argument to be rendered in bold, which causes confusion with the [+]number argument right above it. ok wiz@@ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.128 2017/03/23 12:10:53 kre Exp $ d1704 1 a1704 1 .It [+]number d1709 1 a1709 1 .It \-number @ 1.128 log @ PR bin/14578 Add a reference to editline(7) so we document the "-o vi" and "-o emacs" bindings (defaults, and what can be set.) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.127 2017/03/20 22:17:56 kre Exp $ d1709 1 a1709 1 .It Fl number @ 1.127 log @ At the suggestion of Matthew Sporleder (on current-users@@) reword some of the description of arithmetic expressions to make it a bit more human friendly. While here fix a few other minor errors, and bump date. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.126 2017/03/20 11:26:07 kre Exp $ d2286 8 d2410 1 @ 1.126 log @ Finish support for all required $(( )) (shell arithmetic) operators, closing PR bin/50958 That meant adding the assignment operators ('=', and all of the +=, *= ...) Currently, ++, --, and ',' are not implemented (none of those are required by posix) but support for them (most likely ',' first) might be added later. To do this, I removed the yacc/lex arithmetic parser completely, and replaced it with a hand written recursive descent parser, that I obtained from FreeBSD, who earlier had obtained it from dash (Herbert Xu). While doing the import, I cleaned up the sources (changed some file names to avoid requiring a clean build, or signifigant surgery to the obj directories if "build.sh -u" was to be used - "build.sh -u" should work fine as it is now) removed some dashisms, applied some KNF, ... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.125 2017/02/04 23:35:15 wiz Exp $ d34 1 a34 1 .Dd February 1, 2017 d1238 3 a1240 2 The expression is treated as if it were in double quotes, except that a double quote inside the expression is not treated specially. d1242 10 a1251 1 command substitution, and quote removal. d1253 2 a1254 2 Next, the shell treats this as an arithmetic expression and substitutes the value of the expression. d1263 1 a1263 1 arithmetic). d1608 1 a1608 1 Variables can also be un-exported using the unset builtin command. d2229 1 a2229 1 with no argumentss, @ 1.125 log @Remove trailing space. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.124 2017/02/02 20:00:40 christos Exp $ d1258 33 @ 1.124 log @Add fdflags builtin. Discussed with Chet and he has implemented it for bash too. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.123 2016/05/12 13:15:43 kre Exp $ d1691 1 a1691 1 The @ 1.123 log @ Document that a N>&N (or N<&N) redirection turns off close-on-exec for N (where N is a decimal fd number) either when used as some-command N>&N (where fd N is passed, open, to some-command - which is obviously what is wanted) Or as exec N>&N which effects fd N for all future commands. Note that this means exec N>foo N>&N returns to the old behaviour of leaving the file descriptor open when commands are run (as do most shells, other than ksh) and works for both new and old NetBSD shells (old ones never set close-on-exec, and treat N>&N as a rather meaingless no-op request, and just ignore it), new ones set close-on-exec on the first redirection, then disable it again on the second. Everything here about >& for output fds applies to <& for input ones. OK christos@@ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.122 2016/05/09 20:36:07 kre Exp $ d34 1 a34 1 .Dd May 9, 2016 d1688 22 @ 1.123.4.1 log @Sync with HEAD @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.131 2017/04/14 08:48:01 abhinav Exp $ d34 1 a34 1 .Dd March 20, 2017 d1238 2 a1239 3 The expression in an arithmetic expansion is treated as if it were in double quotes, except that a double quote character inside the expression is just a normal character (it quotes nothing.) d1241 1 a1241 10 command substitution, and quote removal (the only quoting character is the backslash .Sq \&\e , and only when followed by another .Sq \&\e , a dollar sign .Sq \&$ , a backquote .Sq \&` or a newline.) d1243 2 a1244 2 Next, the shell evaluates the expanded result as an arithmetic expression and substitutes the calculated value of that expression. d1253 1 a1253 1 arithmetic.) a1257 33 Variables that are not set, or which have an empty (null string) value, used this way evaluate as zero (that is, .Dq x in arithmetic, as an R-Value, is evaluated as .Dq ${x:-0} ) unless the .Nm .Fl u flag is set, in which case a reference to an unset variable is an error. Note that unset variables used in the ${var} form expand to a null string, which might result in syntax errors. Referencing the value of a variable which is not numeric is an error. .Pp All of the C expression operators applicable to integers are supported, and operate as they would in a C expression, except the unary .Dq ++ and .Dq -- operators (in both prefix and postfix forms) and the .Dq \&, (comma) operator, which are currently not supported. .Pp It should not be necessary to state that the C operators which operate on, or produce, pointer types, are not supported. Those include unary .Dq \&* and .Dq \&& and the struct and array referencing binary operators: .Dq \&. , .Dq \&-> and .Dq \&[ . d1565 1 a1565 1 Variables can also be un-exported using the unset built in command. d1661 1 a1661 1 .It Oo Cm + Oc Ns Ar number d1666 1 a1666 1 .It Cm \- Ns Ar number a1687 22 .It fdflags Oo Fl v Oc Oo fd ... Oc .It fdflags Oo Fl v Oc Fl s Ar flags fd Oo ... Oc Get or set file descriptor flags. The .Fl v argument enables verbose printing, printing flags that are also off, and the flags of the file descriptor being set after setting. The .Fl s flag interprets the .Ar flags argument as a comma separated list of file descriptor flags, each preceded with a .Dq + or a .Dq - indicating to set or clear the respective flag. Valid flags are: append,async,sync,nonblock,fsync,dsync,rsync,direct,nosigpipe,cloexec. See .Xr fcntl 2 for more information. d1908 1 d2106 1 d2164 1 a2164 1 with no arguments, a2220 8 See .Xr editline 7 for a list of the possible command bindings, and the default settings in .Ar emacs and .Ar vi modes. a2336 1 .Xr editline 7 , @ 1.123.2.1 log @Sync with HEAD @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.125 2017/02/04 23:35:15 wiz Exp $ d34 1 a34 1 .Dd February 1, 2017 a1687 22 .It fdflags Oo Fl v Oc Oo fd ... Oc .It fdflags Oo Fl v Oc Fl s Ar flags fd Oo ... Oc Get or set file descriptor flags. The .Fl v argument enables verbose printing, printing flags that are also off, and the flags of the file descriptor being set after setting. The .Fl s flag interprets the .Ar flags argument as a comma separated list of file descriptor flags, each preceded with a .Dq + or a .Dq - indicating to set or clear the respective flag. Valid flags are: append,async,sync,nonblock,fsync,dsync,rsync,direct,nosigpipe,cloexec. See .Xr fcntl 2 for more information. @ 1.123.2.2 log @Sync with HEAD @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.131 2017/04/14 08:48:01 abhinav Exp $ d34 1 a34 1 .Dd March 20, 2017 d1238 2 a1239 3 The expression in an arithmetic expansion is treated as if it were in double quotes, except that a double quote character inside the expression is just a normal character (it quotes nothing.) d1241 1 a1241 10 command substitution, and quote removal (the only quoting character is the backslash .Sq \&\e , and only when followed by another .Sq \&\e , a dollar sign .Sq \&$ , a backquote .Sq \&` or a newline.) d1243 2 a1244 2 Next, the shell evaluates the expanded result as an arithmetic expression and substitutes the calculated value of that expression. d1253 1 a1253 1 arithmetic.) a1257 33 Variables that are not set, or which have an empty (null string) value, used this way evaluate as zero (that is, .Dq x in arithmetic, as an R-Value, is evaluated as .Dq ${x:-0} ) unless the .Nm .Fl u flag is set, in which case a reference to an unset variable is an error. Note that unset variables used in the ${var} form expand to a null string, which might result in syntax errors. Referencing the value of a variable which is not numeric is an error. .Pp All of the C expression operators applicable to integers are supported, and operate as they would in a C expression, except the unary .Dq ++ and .Dq -- operators (in both prefix and postfix forms) and the .Dq \&, (comma) operator, which are currently not supported. .Pp It should not be necessary to state that the C operators which operate on, or produce, pointer types, are not supported. Those include unary .Dq \&* and .Dq \&& and the struct and array referencing binary operators: .Dq \&. , .Dq \&-> and .Dq \&[ . d1565 1 a1565 1 Variables can also be un-exported using the unset built in command. d1661 1 a1661 1 .It Oo Cm + Oc Ns Ar number d1666 1 a1666 1 .It Cm \- Ns Ar number d1930 1 d2128 1 d2186 1 a2186 1 with no arguments, a2242 8 See .Xr editline 7 for a list of the possible command bindings, and the default settings in .Ar emacs and .Ar vi modes. a2358 1 .Xr editline 7 , @ 1.122 log @ PR bin/48489 -- Shell "simple commands" are now not allowed to be completely empty, they must have something (var assignment, redirect, or command, or multiple of those) to avoid a syntax error. This matches the requirements of the grammar in the standard. Correct the parser (using FreeBSD's sh as a guide) and update the man page to remove text that noted a couple of places this was previously OK. OK christos@@ @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.121 2016/04/04 13:05:56 wiz Exp $ d1541 10 @ 1.121 log @Remove some double quotes. Parity is kept. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.120 2016/03/31 16:18:22 christos Exp $ d34 1 a34 1 .Dd March 31, 2016 a332 1 .\" They can seek me here (that dreaded filesystem) a335 1 .\" then can seek me there (the filesystem, once again) a589 1 .\" But the damned elusive filesystem shall never be defeated! a756 8 Also, if you forget the left-hand side (for example when continuing lines but forgetting to use a backslash) it defaults to a true statement. This behavior is not useful and should not be relied upon. Similarly, if input to the .Nm reaches end of file immediately after one of these operators, it is assumed that a true statement follows. This behavior is also not useful and should not be relied upon. @ 1.120 log @Document the NETBSD_SHELL variable, the enhancements to export, the posix option, and a whole bunch of miscellaneous updates and corrections. (from kre@@) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.119 2016/02/24 15:28:36 wiz Exp $ d883 1 a883 1 .Dq "Hello World d898 1 a898 1 .Ic "here document @ 1.119 log @file system police. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.118 2016/02/24 14:35:51 christos Exp $ d34 1 a34 1 .Dd January 5, 2015 d333 1 d337 1 d357 16 d549 3 a551 1 All the text on successive lines up to the delimiter, or to an EOF, is d561 1 a561 1 .Dq \*[Lt]\*[Lt]- d564 6 a569 1 then leading tabs in the here-doc-text are stripped. d592 1 d726 5 d737 1 a737 1 command and immediately proceed onto the next command; otherwise it waits d794 1 a794 1 for variable in word ... d799 2 a800 1 The words are expanded, and then the list is executed repeatedly with the d805 2 a806 1 .Dq } . d857 1 a857 1 .Dl name ( ) command d865 37 d909 1 a909 1 .Dq Local d912 2 a913 1 When a variable is made local, it inherits the initial value and exported d917 15 d937 9 d954 5 d963 3 a965 1 It terminates the currently executing function. d967 7 d994 15 a1008 1 built-in can also be used to set or reset them. d1062 6 d1155 1 a1155 1 .It ${parameter:-word} d1272 5 a1276 2 expansions and substitutions that did not occur in double quotes for field splitting and multiple fields can result. d1280 1 a1280 1 as a delimiter and use the delimiters to split the results of parameter d1285 1 a1285 1 are treated strictly as parameter terminators. d1289 18 d1310 8 a1317 1 is unset it is assumed to contain space, tab, and newline. d1380 1 a1380 1 .Pq Dq - . d1392 1 a1392 1 .Dq - , d1407 1 a1407 1 Any arguments are ignored. d1415 1 a1415 1 variable if it does not contain a directory separator d1419 1 a1419 1 The POSIX standard is unclear on how loop control keywords (break d1423 1 d1448 1 a1448 1 have a shell function with the same name as a built-in command.) d1558 4 a1561 3 .It export Ar name ... .It export Fl p The specified names are exported so that they will appear in the d1563 20 a1582 1 The only way to un-export a variable is to unset it. d1588 4 a1591 1 With no arguments the export command lists the names of all exported variables. d1595 13 d1957 2 a1958 1 A d1962 1 a1962 1 to the value of d1966 1 a1966 1 to the value of d1972 4 a1975 3 If there are zero positional parameters, .Ic shift does nothing. d2029 3 a2031 1 Print date upon receiving signal INT d2120 33 a2152 4 .It unset Ar name ... The specified variables and functions are unset and unexported. If a given name corresponds to both a variable and a function, both the variable and the function are unset. d2155 2 a2156 1 last process in the job. d2159 9 d2224 6 d2238 7 a2244 2 .It Ev PATH The default search path for executables. d2246 2 a2247 8 .Sx Path Search section above. .It Ev CDPATH The search path used with the .Ic cd built-in. .It Ev LINENO The current line number in the script or function. d2253 2 d2275 5 a2291 10 .It Ev IFS Input Field Separators. This is normally set to .Aq space , .Aq tab , and .Aq newline . See the .Sx White Space Splitting section for more details. d2296 12 a2307 2 .It Ev HISTSIZE The number of lines in the history buffer for the shell. d2357 2 @ 1.118 log @Make sh.1 catch up with reality. Document -h (such as it is...) and also added doc for some other stuff that was missing. Take the opportunity to clean up the way the flags are set in the man page, so every new flag doesn't have to be added 6 times! (Some of the lists were different from others, in ordering, and content, for no good reason at all.) Make a few other cleanups ... Add text about AND-OR lists, This can be also used to justify closing an open PR: (that "sh -c 'command &&'" is not a syntax error...). Add doc for -F, which should default to set if the shell somehow gets compiled without DO_SHAREDVFORK defined, (to be committed separately) XXX: Consider disabling DO_SHAREDVFORK if SMALL is defined? From kre @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.117 2016/01/06 00:22:21 wiz Exp $ d332 1 a332 1 Bind commands in functions to filesystem paths when the function is defined. d334 1 a334 1 the filesystem is searched for commands each time the function is invoked. @ 1.117 log @Whitespace. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.116 2016/01/05 18:16:20 christos Exp $ d36 1 d44 2 a45 2 .Op Fl aCefnuvxIimqVEb .Op Cm +aCefnuvxIimqVEb d57 2 a58 2 .Op Fl abCEefnuvxIimpqV .Op Cm +abCEefnuvxIimpqV d71 2 a72 2 .Op Fl abCEefnuvxIimpqV .Op Cm +abCEefnuvxIimpqV d226 5 d247 3 d251 5 d293 1 a293 1 This option has no effect when set after the shell has d316 20 d348 7 d732 5 d1623 1 a1623 1 to set keybindings as defined by @ 1.116 log @Document close-on-exec redirection behavior. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.115 2015/05/26 21:35:15 christos Exp $ d1335 1 a1335 1 (see @ 1.115 log @Drop privileges when executed set{u,g}id unless -p is specified like other shells do to avoid system() and popen() abuse. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.114 2014/06/01 17:46:06 christos Exp $ d34 1 a34 1 .Dd May 26, 2015 d1334 14 @ 1.114 log @PR/48843: Jarmo Jaakkola: Soften the language in the manual page, making less promises about behavior not explicitly stated in the standard. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.113 2014/05/31 14:42:18 christos Exp $ d34 1 a34 1 .Dd June 1, 2014 d56 2 a57 2 .Op Fl aCefnuvxIimqVEb .Op Cm +aCefnuvxIimqVEb d70 2 a71 2 .Op Fl aCefnuvxIimqVEb .Op Cm +aCefnuvxIimqVEb d302 7 @ 1.113 log @PR/48843: Jarmo Jaakkola: dot commands mess up scope nesting tracking Evaluation of commands goes completely haywire if a file containing a break/continue/return command outside its "intended" scope is sourced using a dot command inside its "intended" scope. The main symptom is not exiting from the sourced file when supposed to, leading to evaluation of commands that were not supposed to be evaluated. A secondary symptom is that these extra commands are not evaluated correctly, as some of them are skipped. Some examples are listed in the How-To-Repeat section. According to the POSIX standard, this is how it should work: dot: The shell shall execute commands from the file in the current environment. break: The break utility shall exit from the smallest enclosing for, while, or until loop, [...] continue: The continue utility shall return to the top of the smallest enclosing for, while, or until loop, [...] return: The return utility shall cause the shell to stop executing the current function or dot script. If the shell is not currently executing a function or dot script, the results are unspecified. It is clear that return should return from a sourced file, which it does not do. Whether break and continue should work from the sourced file might be debatable. Because the dot command says "in the current environment", I'd say yes. In any case, it should not fail in weird ways like it does now! The problems occur with return (a) and break/continue (b) because: 1) dotcmd() does not record the function nesting level prior to sourcing the file nor does it touch the loopnest variable, leading to either 2 a) returncmd() being unable to detect that it should not set evalskip to SKIPFUNC but SKIPFILE, or b) breakcmd() setting evalskip to SKIPCONT or SKIPBREAK, leading to 3) cmdloop() not detecting that it should skip the rest of the file, due to only checking for SKIPFILE. The result is that cmdloop() keeps executing lines from the file whilst evalskip is set, which is the main symptom. Because evalskip is checked in multiple places in eval.c, the secondary symptom appears. >How-To-Repeat: Run the following script: printf "break\necho break1; echo break2" >break printf "continue\necho continue1; echo continue2" >continue printf "return\necho return1; echo return2" >return while true; do . ./break; done for i in 1 2; do . ./continue; done func() { . ./return } func No output should be produced, but instead this is the result: break1 continue1 continue1 return1 The main symptom is evident from the unexpected output and the secondary one from the fact that there are no lines with '2' in them. >Fix: Here is patch to src/bin/sh to fix the above problems. It keeps track of the function nesting level at the beginning of a dot command to enable the return command to work properly. I also changed the undefined-by-standard functionality of the return command when it's not in a dot command or function from (indirectly) exiting the shell to being silently ignored. This was done because the previous way has at least one bug: the shell exits without asking for confirmation when there are stopped jobs. Because I read the standard to mean that break and continue should have an effect outside the sourced file, that's how I implemented it. For what it's worth, this also seems to be what bash does. Also laziness, because this way required no changes to loopnesting tracking. If this is not wanted, it might make sense to move the nesting tracking to the inputfile stack. The patch also does some clean-up to reduce the amount of global variables by moving the dotcmd() and the find_dot_file() functions from main.c to eval.c and making in_function() a proper function. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.112 2014/01/20 14:05:51 roy Exp $ d34 1 a34 1 .Dd January 20, 2014 d1209 4 a1212 3 A non-obvious consequence of the file executing in the current environment is that loop control keywords (continue and break) can be used in the file to control loops surrounding the dot command. d1657 7 a1663 5 The effects of using a return command outside a function or a dot command are not standardized. This implementation (currently) treats such a return as a no-op with a return value of 0 (success, true). Use the exit command if you want to return from a script or exit your shell. @ 1.112 log @Add wctype(3) support to Shell Patterns. Obtained from FreeBSD. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.111 2013/10/02 20:42:56 christos Exp $ d1195 1 a1195 1 .It : d1197 1 d1199 13 a1211 1 The commands in the specified file are read and executed by the shell. d1648 13 @ 1.112.2.1 log @Rebase. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.114 2014/06/01 17:46:06 christos Exp $ d34 1 a34 1 .Dd June 1, 2014 d1195 1 a1195 1 .It : [ Ar arg ... ] a1196 1 Any arguments are ignored. d1198 1 a1198 14 The dot command reads and executes the commands from the specified .Ar file in the current shell environment. The file does not need to be executable and is looked up from the directories listed in the .Ev PATH variable if it does not contain a directory separator .Pq Sq / . The return command can be used for a premature return from the sourced file. .Pp The POSIX standard is unclear on how loop control keywords (break and continue) behave across a dot command boundary. This implementation allows them to control loops surrounding the dot command, but obviously such behavior should not be relied on. a1634 15 .It return [ Ar n ] Stop executing the current function or a dot command with return value of .Ar n or the value of the last executed command, if not specified. For portability, .Ar n should be in the range from 0 to 255. .Pp The POSIX standard says that the results of .Sq return outside a function or a dot command are unspecified. This implementation treats such a return as a no-op with a return value of 0 (success, true). Use the exit command instead, if you want to return from a script or exit your shell. @ 1.111 log @document LINENO XXX: someone should fix all the .Ev stuff because some of them are just shell variables .Va and are not really exported to the environment. See the FreeBSD man page. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.110 2013/05/09 11:43:27 simonb Exp $ d34 1 a34 1 .Dd October 2, 2013 d1160 9 @ 1.110 log @Document that a here-document can finish at an EOF as well as at the delimiter. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.109 2012/10/03 19:37:36 wiz Exp $ d34 1 a34 1 .Dd May 9, 2013 d1899 2 @ 1.109 log @- Correct macro usage; - improve wording, including creating more consistency therein. From Bug Hunting. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.108 2012/08/26 14:30:38 wiz Exp $ d34 1 a34 1 .Dd August 26, 2012 d483 3 a485 3 All the text on successive lines up to the delimiter is saved away and made available to the command on standard input, or file descriptor n if it is specified. @ 1.108 log @- improve punctuation; - improve (create more consistency in) spelling; - remove unnecessary (and in part ignored) macros, as well as an unnecessary argument to `.Bl' (fixes mandoc(1) warnings); - improve wording; - bump date. Patch from Bug Hunting. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.107 2012/06/11 18:28:10 njoly Exp $ d419 3 a421 3 The remaining words are expanded as described in the section called .Dq Expansions , d487 1 a487 1 quoted, then the here-doc-text is treated literally, otherwise the text is d489 3 a491 2 expansion (as described in the section on .Dq Expansions ) . d890 1 a890 1 This clause describes the various expansions that are performed on words. d1589 3 a1591 2 line and the line is split as described in the section on word splitting above, and the pieces are assigned to the variables in order. d1634 3 a1636 2 flags, or clears them as described in the section called .Sx Argument List Processing . d1833 3 a1835 2 in .Sx Built-ins ) d1892 3 a1894 2 See the above section .Sx Path Search . @ 1.108.2.1 log @Resync to 2012-11-19 00:00:00 UTC @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.109 2012/10/03 19:37:36 wiz Exp $ d419 3 a421 3 The remaining words are expanded as described in the .Sx Word Expansions section below, d487 1 a487 1 quoted, then the here-doc-text is treated literally; otherwise, the text is d489 2 a490 3 expansion as described in the .Sx Word Expansions section below. d889 1 a889 1 This section describes the various expansions that are performed on words. d1588 2 a1589 3 line and the line is split as described in the .Sx Word Expansions section above, and the pieces are assigned to the variables in order. d1632 2 a1633 3 flags, or clears them as described in the .Sx Argument List Processing section. d1830 2 a1831 3 in the .Sx Built-ins section) d1888 2 a1889 3 See the .Sx Path Search section above. @ 1.108.2.2 log @resync from head @ text @d1 1 a1 1 .\" $NetBSD$ d34 1 a34 1 .Dd May 9, 2013 d483 3 a485 3 All the text on successive lines up to the delimiter, or to an EOF, is saved away and made available to the command on standard input, or file descriptor n if it is specified. @ 1.108.2.3 log @Rebase to HEAD as of a few days ago. @ text @d34 1 a34 1 .Dd June 1, 2014 a1159 9 A named class of characters (see .Xr wctype 3 ) may be specified by surrounding the name with .Pq Dq [: and .Pq Dq :] . For example, .Pq Dq [[:alpha:]] is a shell pattern that matches a single letter. d1186 1 a1186 1 .It : [ Ar arg ... ] a1187 1 Any arguments are ignored. d1189 1 a1189 14 The dot command reads and executes the commands from the specified .Ar file in the current shell environment. The file does not need to be executable and is looked up from the directories listed in the .Ev PATH variable if it does not contain a directory separator .Pq Sq / . The return command can be used for a premature return from the sourced file. .Pp The POSIX standard is unclear on how loop control keywords (break and continue) behave across a dot command boundary. This implementation allows them to control loops surrounding the dot command, but obviously such behavior should not be relied on. a1625 15 .It return [ Ar n ] Stop executing the current function or a dot command with return value of .Ar n or the value of the last executed command, if not specified. For portability, .Ar n should be in the range from 0 to 255. .Pp The POSIX standard says that the results of .Sq return outside a function or a dot command are unspecified. This implementation treats such a return as a no-op with a return value of 0 (success, true). Use the exit command instead, if you want to return from a script or exit your shell. a1898 2 .It Ev LINENO The current line number in the script or function. @ 1.107 log @Allow thread limit queries by adding the new -r flag to ulimit. Add the corresponding documentation in the man page. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.106 2011/10/05 13:15:30 christos Exp $ d34 1 a34 1 .Dd June 11, 2012 d236 1 a236 1 .Ic until ; d348 1 a348 1 single-quotes in a single-quoted string). a757 1 .Pp d851 1 a851 1 When the expansion occurs within double-quotes, each positional d898 1 a898 1 rule is the expansion of the special parameter @@ within double-quotes, as d956 1 a956 1 If a parameter expansion occurs inside double-quotes: a993 3 .El .Pp .Bl -tag -width aaparameterwordaaaaa d1005 1 a1005 1 Enclosing the full parameter expansion string in double-quotes does not d1066 2 a1067 2 The expression is treated as if it were in double-quotes, except that a double-quote inside the expression is not treated specially. d1089 1 a1089 1 expansions and substitutions that did not occur in double-quotes for d1135 1 a1135 1 and the dollar sign or back quotes are not double quoted, d1143 3 a1145 1 A question mark matches any single character. d1149 1 a1149 1 The end of the character class is indicated by a d1151 1 a1151 1 if the d1159 2 a1160 1 A range of characters may be specified using a minus sign. d1162 3 a1164 1 by making an exclamation point the first character of the character class. d1171 3 a1173 1 To include a minus sign, make it the first or last character listed. a1486 1 .Pp a1499 1 .Pp d1949 1 a1949 1 .Bl -item -width HOMEprofilexxxx @ 1.106 log @Merge duplicate information. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.105 2011/10/04 18:11:27 apb Exp $ d34 1 a34 1 .Dd October 4, 2011 d1734 1 a1734 1 .It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl tfdscmlpnv Oo Ar value Oc Oc d1780 3 @ 1.106.2.1 log @sync with head @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.106 2011/10/05 13:15:30 christos Exp $ d34 1 a34 1 .Dd August 26, 2012 d236 1 a236 1 .Ic until , d348 1 a348 1 single quotes in a single-quoted string). d419 3 a421 3 The remaining words are expanded as described in the .Sx Word Expansions section below, d487 1 a487 1 quoted, then the here-doc-text is treated literally; otherwise, the text is d489 2 a490 3 expansion as described in the .Sx Word Expansions section below. d758 1 d852 1 a852 1 When the expansion occurs within double quotes, each positional d890 1 a890 1 This section describes the various expansions that are performed on words. d899 1 a899 1 rule is the expansion of the special parameter @@ within double quotes, as d957 1 a957 1 If a parameter expansion occurs inside double quotes: d995 3 d1009 1 a1009 1 Enclosing the full parameter expansion string in double quotes does not d1070 2 a1071 2 The expression is treated as if it were in double quotes, except that a double quote inside the expression is not treated specially. d1093 1 a1093 1 expansions and substitutions that did not occur in double quotes for d1139 1 a1139 1 and the dollar sign or backquotes are not double-quoted, d1147 1 a1147 3 A question mark .Pq Dq \&? matches any single character. d1151 1 a1151 1 The end of the character class is indicated by a right bracket d1153 1 a1153 1 if this d1161 1 a1161 2 A range of characters may be specified using a minus sign .Pq Dq - . d1163 1 a1163 3 by making an exclamation mark .Pq Dq \&! the first character of the character class. d1170 1 a1170 3 To include a .Dq - , make it the first or last character listed. d1484 1 d1498 1 d1587 2 a1588 3 line and the line is split as described in the .Sx Word Expansions section above, and the pieces are assigned to the variables in order. d1631 2 a1632 3 flags, or clears them as described in the .Sx Argument List Processing section. d1734 1 a1734 1 .It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl btfdscmlrpnv Oo Ar value Oc Oc a1779 3 .It Fl r show or set the limit on the number of threads this user can have at one time d1826 2 a1827 3 in the .Sx Built-ins section) d1884 2 a1885 3 See the .Sx Path Search section above. d1945 1 a1945 1 .Bl -item @ 1.106.2.2 log @sync with head. for a reference, the tree before this commit was tagged as yamt-pagecache-tag8. this commit was splitted into small chunks to avoid a limitation of cvs. ("Protocol error: too many arguments") @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.106.2.1 2012/10/30 18:46:08 yamt Exp $ d34 1 a34 1 .Dd January 20, 2014 d483 3 a485 3 All the text on successive lines up to the delimiter, or to an EOF, is saved away and made available to the command on standard input, or file descriptor n if it is specified. a1159 9 A named class of characters (see .Xr wctype 3 ) may be specified by surrounding the name with .Pq Dq [: and .Pq Dq :] . For example, .Pq Dq [[:alpha:]] is a shell pattern that matches a single letter. a1898 2 .It Ev LINENO The current line number in the script or function. @ 1.105 log @.Dq Dv \&: @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.104 2011/10/04 18:07:39 christos Exp $ d970 2 a971 2 is omitted in the modifiers, then the expansion is applied only to unset parameters, not null ones. a996 3 In the parameter expansions shown previously, use of the colon in the format results in a test for a parameter that is unset or null; omission of the colon results in a test for a parameter that is only unset. @ 1.104 log @Mention what happens when we don't include :. It would be nice to use .Dv : but it produces ``'': @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.103 2011/09/11 06:02:20 dholland Exp $ d969 1 a969 1 .Dv : @ 1.103 log @A feature that wasn't implemented for 4.4alpha and still isn't implemented is just plain not implemented. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.102 2011/06/13 20:41:00 wiz Exp $ d34 1 a34 1 .Dd June 11, 2011 d968 4 @ 1.102 log @Sort sections. Remove trailing whitespace. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.101 2011/06/13 00:17:15 uebayasi Exp $ d301 1 a301 1 (UNIMPLEMENTED for 4.4alpha) @ 1.101 log @Typos. @ text @d1 1 a1 1 .\" $NetBSD$ d1685 1 a1685 1 omitted or set to a1870 9 .Sh EXIT STATUS Errors that are detected by the shell, such as a syntax error, will cause the shell to exit with a non-zero exit status. If the shell is not an interactive shell, the execution of the shell file will be aborted. Otherwise the shell will return the exit status of the last command executed, or if the exit built-in is used with a numeric argument, it will return the argument. d1950 9 @ 1.100 log @document OLDPWD and cd - @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.99 2010/06/03 02:05:02 dholland Exp $ d1241 1 a1241 1 then she current working directory is changed to the previous current d1686 2 a1687 1 .Sq - the specified signals are set to their default action. @ 1.99 log @Note that set -o tabcomplete requires either set -o emacs or set -o vi to work. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.98 2010/03/01 21:53:58 joerg Exp $ d34 1 a34 1 .Dd June 2, 2010 d1237 7 d1264 1 a1264 1 with the specified directory and change to that directory. d1267 4 d1275 1 a1275 1 with incorrect information and to change the current directory d1493 1 a1493 1 shift `expr $OPTIND - 1` d1685 2 a1686 1 omitted or set to `-' the specified signals are set to their default action. @ 1.99.4.1 log @Catchup with rmind-uvmplock merge. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.102 2011/06/13 20:41:00 wiz Exp $ d34 1 a34 1 .Dd June 11, 2011 a1236 7 If .Ar directory is .Sq - , then the current working directory is changed to the previous current working directory as set in .Ev OLDPWD . d1257 1 a1257 1 with the specified physical directory path and change to that directory. a1259 4 When the directory changes, the variable .Ev OLDPWD is set to the working directory before the change. .Pp d1264 1 a1264 1 with the logical path and to change the current directory d1482 1 a1482 1 shift $(expr $OPTIND - 1) d1674 1 a1674 3 omitted or set to .Sq - the specified signals are set to their default action. d1858 9 a1945 9 .Sh EXIT STATUS Errors that are detected by the shell, such as a syntax error, will cause the shell to exit with a non-zero exit status. If the shell is not an interactive shell, the execution of the shell file will be aborted. Otherwise the shell will return the exit status of the last command executed, or if the exit built-in is used with a numeric argument, it will return the argument. @ 1.98 log @\\ -> \e @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.97 2010/01/01 21:46:31 wiz Exp $ d34 1 a34 1 .Dd January 1, 2010 d313 5 @ 1.97 log @Bump date for cd -P support. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.96 2010/01/01 19:51:19 dholland Exp $ d1474 1 a1474 1 \\?) echo $USAGE; exit 1;; @ 1.96 log @fix another typo @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.95 2010/01/01 19:34:59 dholland Exp $ d34 1 a34 1 .Dd March 29, 2009 @ 1.95 log @Make the cd builtin accept and ignore -P, which is a kshism that has been allowed to leak into POSIX and selects the behavior cd already implements. Closes PR bin/42557 and also relevant to PR pkg/42168. I suppose this should probably be pulled up to both -4 and -5... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.94 2010/01/01 18:09:16 dholland Exp $ d1530 1 a1530 1 is checked to see if it refers to the current directory, if it does @ 1.94 log @fix typo @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.93 2009/03/29 08:55:27 wiz Exp $ d1222 1 a1222 1 .It cd Op Ar directory Op Ar replace d1248 15 d1543 1 a1543 1 command doesn't currently support d1545 1 a1545 3 or .Fl P and will cache (almost) the absolute path. @ 1.93 log @Bump date for previous. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.92 2009/03/29 01:02:49 mrg Exp $ d1521 1 a1521 1 is set to printed value. @ 1.92 log @- add new RLIMIT_AS (aka RLIMIT_VMEM) resource that limits the total address space available to processes. this limit exists in most other modern unix variants, and like most of them, our defaults are unlimited. remove the old mmap / rlimit.datasize hack. - adds the VMCMD_STACK flag to all the stack-creation vmcmd callers. it is currently unused, but was added a few years ago. - add a pair of new process size values to kinfo_proc2{}. one is the total size of the process memory map, and the other is the total size adjusted for unused stack space (since most processes have a lot of this...) - patch sh, and csh to notice RLIMIT_AS. (in some cases, the alias RLIMIT_VMEM was already present and used if availble.) - patch ps, top and systat to notice the new k_vm_vsize member of kinfo_proc2{}. - update irix, svr4, svr4_32, linux and osf1 emulations to support this information. (freebsd could be done, but that it's best left as part of the full-update of compat/freebsd.) this addresses PR 7897. it also gives correct memory usage values, which have never been entirely correct (since mmap), and have been very incorrect since jemalloc() was enabled. tested on i386 and sparc64, build tested on several other platforms. thanks to many folks for feedback and testing but most espcially chuq and yamt for critical suggestions that lead to this patch not having a special ugliness i wasn't happy with anyway :-) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.91 2009/03/10 15:14:28 joerg Exp $ d34 1 a34 1 .Dd June 24, 2007 @ 1.91 log @Explicitly escape -- as it is not an argment to the Cm macro. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.90 2009/03/10 14:18:52 joerg Exp $ d1702 1 a1702 1 .It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl tfdscmlpn Oo Ar value Oc Oc d1753 2 @ 1.90 log @Don't use .Xo/.Xc to workaround ancient macro argument limit. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.89 2009/03/09 19:24:26 joerg Exp $ d1593 1 a1593 1 .It set Oo { Fl options | Cm +options | Cm -- } Oc Ar arg ... @ 1.89 log @Fix preamble to match order set out by mdoc(7). Discussed with wiz. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.88 2008/12/11 04:34:45 yamt Exp $ d1200 1 a1200 7 .It Xo command .Op Fl p .Op Fl v .Op Fl V .Ar command .Op Ar arg ... .Xc d1288 3 a1290 10 .It Xo fc Op Fl e Ar editor .Op Ar first Op Ar last .Xc .It Xo fc Fl l .Op Fl nr .Op Ar first Op Ar last .Xc .It Xo fc Fl s Op Ar old=new .Op Ar first .Xc d1509 1 a1509 1 .It pwd Op Fl LP d1551 1 a1551 5 .It Xo read Op Fl p Ar prompt .Op Fl r .Ar variable .Op Ar ... .Xc d1593 1 a1593 5 .It Xo set .Oo { .Fl options | Cm +options | Cm -- } .Oc Ar arg ... .Xc d1641 2 a1642 7 .It Xo trap .Op Fl l .Xc .It Xo trap .Op Ar action .Ar signal ... .Xc d1702 1 a1702 4 .It ulimit Xo .Op Fl H \*(Ba Fl S .Op Fl a \*(Ba Fl tfdscmlpn Op Ar value .Xc a1721 1 .Bl -tag -width Fl d1724 1 d1769 1 a1769 4 .It unalias Xo .Op Fl a .Op Ar name .Xc @ 1.88 log @document "EXIT" pseudo signal. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.87 2007/06/24 17:57:56 christos Exp $ d35 1 a36 1 .Dt SH 1 @ 1.88.2.1 log @Sync with HEAD. Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.93 2009/03/29 08:55:27 wiz Exp $ d34 2 a35 1 .Dd March 29, 2009 a36 1 .Os d1200 7 a1206 1 .It command Oo Fl p Oc Oo Fl v Oc Oo Fl V Oc Ar command Oo Ar arg ... Oc d1294 10 a1303 3 .It fc Oo Fl e Ar editor Oc Oo Ar first Oo Ar last Oc Oc .It fc Fl l Oo Fl nr Oc Oo Ar first Oo Ar last Oc Oc .It fc Fl s Oo Ar old=new Oc Oo Ar first Oc d1522 1 a1522 1 .It pwd Op Fl \&LP d1564 5 a1568 1 .It read Oo Fl p Ar prompt Oc Oo Fl r Oc Ar variable Oo Ar ... Oc d1610 5 a1614 1 .It set Oo { Fl options | Cm +options | Cm \-- } Oc Ar arg ... d1662 7 a1668 2 .It trap Oo Fl l Oc .It trap Oo Ar action Oc Ar signal ... d1728 4 a1731 1 .It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl tfdscmlpnv Oo Ar value Oc Oc d1751 1 a1753 1 .Bl -tag -width Fl a1781 2 .It Fl v show or set the limit on how large a process address space can be d1798 4 a1801 1 .It unalias Oo Fl a Oc Oo Ar name Oc @ 1.87 log @PR/36533: Greg A. Woods: minor doc fixes for sh(1) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.86 2007/03/25 06:56:43 apb Exp $ d1675 2 a1676 1 .Li 0 , @ 1.87.18.1 log @Pull up following revision(s) (requested by mrg in ticket #622): bin/csh/csh.1: revision 1.46 bin/csh/func.c: revision 1.37 bin/ps/print.c: revision 1.111 bin/ps/ps.c: revision 1.74 bin/sh/miscbltin.c: revision 1.38 bin/sh/sh.1: revision 1.92 via patch external/bsd/top/dist/machine/m_netbsd.c: revision 1.7 lib/libkvm/kvm_proc.c: revision 1.82 sys/arch/mips/mips/cpu_exec.c: revision 1.55 sys/compat/darwin/darwin_exec.c: revision 1.57 sys/compat/ibcs2/ibcs2_exec.c: revision 1.73 sys/compat/irix/irix_resource.c: revision 1.15 sys/compat/linux/arch/amd64/linux_exec_machdep.c: revision 1.16 sys/compat/linux/arch/i386/linux_exec_machdep.c: revision 1.12 sys/compat/linux/common/linux_limit.h: revision 1.5 sys/compat/osf1/osf1_resource.c: revision 1.14 sys/compat/svr4/svr4_resource.c: revision 1.18 sys/compat/svr4_32/svr4_32_resource.c: revision 1.17 sys/kern/exec_subr.c: revision 1.62 sys/kern/init_sysctl.c: revision 1.160 sys/kern/kern_exec.c: revision 1.288 sys/kern/kern_resource.c: revision 1.151 sys/sys/param.h: patch sys/sys/resource.h: revision 1.31 sys/sys/sysctl.h: revision 1.184 sys/uvm/uvm_extern.h: revision 1.153 sys/uvm/uvm_glue.c: revision 1.136 sys/uvm/uvm_mmap.c: revision 1.128 usr.bin/systat/ps.c: revision 1.32 - - add new RLIMIT_AS (aka RLIMIT_VMEM) resource that limits the total address space available to processes. this limit exists in most other modern unix variants, and like most of them, our defaults are unlimited. remove the old mmap / rlimit.datasize hack. - - adds the VMCMD_STACK flag to all the stack-creation vmcmd callers. it is currently unused, but was added a few years ago. - - add a pair of new process size values to kinfo_proc2{}. one is the total size of the process memory map, and the other is the total size adjusted for unused stack space (since most processes have a lot of this...) - - patch sh, and csh to notice RLIMIT_AS. (in some cases, the alias RLIMIT_VMEM was already present and used if availble.) - - patch ps, top and systat to notice the new k_vm_vsize member of kinfo_proc2{}. - - update irix, svr4, svr4_32, linux and osf1 emulations to support this information. (freebsd could be done, but that it's best left as part of the full-update of compat/freebsd.) this addresses PR 7897. it also gives correct memory usage values, which have never been entirely correct (since mmap), and have been very incorrect since jemalloc() was enabled. tested on i386 and sparc64, build tested on several other platforms. thanks to many folks for feedback and testing but most espcially chuq and yamt for critical suggestions that lead to this patch not having a special ugliness i wasn't happy with anyway :-) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.87 2007/06/24 17:57:56 christos Exp $ d1729 1 a1729 1 .Op Fl a \*(Ba Fl tfdscmlpnv Op Ar value a1780 2 .It Fl v show or set the limit on how large a process address space can be @ 1.87.18.1.4.1 log @sync to netbsd-5 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.87.18.3 2010/01/30 19:26:39 snj Exp $ d34 1 a34 1 .Dd January 1, 2010 d1228 1 a1228 1 .It cd Oo Fl P Oc Op Ar directory Op Ar replace a1253 15 The .Fl P option instructs the shell to update .Ev PWD with the specified directory and change to that directory. This is the default. .Pp Some shells also support a .Fl L option, which instructs the shell to update .Ev PWD with incorrect information and to change the current directory accordingly. This is not supported. .Pp d1541 1 a1541 1 command doesn't currently support the d1543 3 a1545 1 option and will cache (almost) the absolute path. @ 1.87.18.2 log @Pull up following revision(s) (requested by dholland in ticket #1274): bin/sh/cd.c: revision 1.40 bin/sh/sh.1: revision 1.95 Make the cd builtin accept and ignore -P, which is a kshism that has been allowed to leak into POSIX and selects the behavior cd already implements. Closes PR bin/42557 and also relevant to PR pkg/42168. I suppose this should probably be pulled up to both -4 and -5... @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.87.18.1 2009/04/01 00:25:21 snj Exp $ d1228 1 a1228 1 .It cd Oo Fl P Oc Op Ar directory Op Ar replace a1253 15 The .Fl P option instructs the shell to update .Ev PWD with the specified directory and change to that directory. This is the default. .Pp Some shells also support a .Fl L option, which instructs the shell to update .Ev PWD with incorrect information and to change the current directory accordingly. This is not supported. .Pp d1541 1 a1541 1 command doesn't currently support the d1543 3 a1545 1 option and will cache (almost) the absolute path. @ 1.87.18.3 log @Pull up following revision(s) (requested by dholland in ticket #1274): bin/sh/sh.1: revision 1.97 via patch Bump date for cd -P support. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.87.18.2 2010/01/30 19:24:32 snj Exp $ d34 1 a34 1 .Dd January 1, 2010 @ 1.86 log @Document that shell arithmetic now uses intmax_t. Document that variables in shell arithmetic don't need "$" signs. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.85 2006/09/04 20:30:36 dsl Exp $ d34 1 a34 1 .Dd March 25, 2007 d675 3 d781 2 a782 1 Local is implemented as a built-in command. d1170 1 a1170 1 be built-in for efficiency (e.g. d1220 3 a1222 1 This is the same as the type built-in. d1831 3 a1833 1 enables vi-mode editing and places sh into vi insert mode. d1838 3 a1840 1 The vi mode uses commands similar to a subset of those described in the d1844 6 a1849 2 enabled, sh can be switched between insert mode and command mode. It's similar to vi: typing d1851 2 a1852 2 will throw you into command VI command mode. Hitting d1854 1 a1854 1 while in command mode will pass the line to the shell. d1856 6 a1861 2 The emacs mode uses commands similar to a subset available in the emacs editor. d1886 2 a1887 1 cd built-in. d1893 3 a1895 1 The search path used with the cd built-in. @ 1.85 log @Fix typo, update date. Fixes PR/34472 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.84 2005/09/10 22:09:43 wiz Exp $ d34 1 a34 1 .Dd September 4, 2006 d1067 13 @ 1.85.2.1 log @Pull up following revision(s) (requested by apb in ticket #570): bin/sh/expand.c: revision 1.78 bin/sh/arith.y: revision 1.18 bin/sh/expand.h: revision 1.17 regress/bin/sh/expand.sh: revision 1.4 bin/sh/sh.1: revision 1.86 bin/sh/arith_lex.l: revision 1.14 Make /bin/sh use intmax_t (instead of int) for arithmetic in $((...)). @ text @d1 1 a1 1 .\" $NetBSD$ d34 1 a34 1 .Dd March 25, 2007 a1066 13 .Pp Arithmetic expressions use a syntax similar to that of the C language, and are evaluated using the .Ql intmax_t data type (this is an extension to .Tn POSIX , which requires only .Ql long arithmetic). Shell variables may be referenced by name inside an arithmetic expression, without needing a .Dq \&$ sign. @ 1.85.2.2 log @Pull up following revision(s) (requested by dholland in ticket #1380): bin/sh/cd.c: revision 1.40 bin/sh/sh.1: revision 1.95 bin/sh/sh.1: revision 1.97 Make the cd builtin accept and ignore -P, which is a kshism that has been allowed to leak into POSIX and selects the behavior cd already implements. Closes PR bin/42557 and also relevant to PR pkg/42168. I suppose this should probably be pulled up to both -4 and -5... Bump date for cd -P support. @ text @d34 1 a34 1 .Dd January 1, 2010 d1222 1 a1222 1 .It cd Oo Fl P Oc Op Ar directory Op Ar replace a1247 15 The .Fl P option instructs the shell to update .Ev PWD with the specified directory and change to that directory. This is the default. .Pp Some shells also support a .Fl L option, which instructs the shell to update .Ev PWD with incorrect information and to change the current directory accordingly. This is not supported. .Pp d1535 1 a1535 1 command doesn't currently support the d1537 3 a1539 1 option and will cache (almost) the absolute path. @ 1.84 log @In mdoc, use .Pp for new paragraphs, not .br. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.83 2005/08/20 21:07:42 dsl Exp $ d34 1 a34 1 .Dd August 20, 2005 d793 1 a793 1 local any shell options that are changed via the set command inside the @ 1.83 log @Don't apply CDPATH if the the first component of the target is "." or "..". Fixes PR/30973 and applies the principle of least surprise. Update documentation to match (including date). (matches behaviour of pdksh - if not it's documentation) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.82 2005/07/15 22:33:48 wiz Exp $ d1234 1 a1234 1 .br @ 1.82 log @Aspell, fix an Xref, drop trailing whitespace. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.81 2005/07/15 17:23:48 christos Exp $ d34 1 a34 1 .Dd July 15, 2005 d1225 3 a1227 2 is set and the directory name does not begin with a slash, then the directories listed in d1234 1 @ 1.81 log @Allow trap to work on ignored signals when the shell is interactive. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.80 2005/05/24 00:03:52 wiz Exp $ d118 1 a118 1 If no args are present and if the standard input of the shell d213 1 a213 1 builtin (described later). d271 1 a271 1 Ignore EOF's from input when interactive. d346 1 a346 1 meaning of all characters except dollarsign d371 1 a371 1 builtin command. d492 1 a492 1 There are three types of commands: shell functions, builtin commands, and d507 1 a507 1 Shell builtins are executed internally to the shell, without spawning a d510 1 a510 1 Otherwise, if the command name doesn't match a function or builtin, the d535 2 a536 2 Then it looks for a builtin command by that name. If a builtin command is not found, one of two things happen: d560 1 a560 1 Additionally, the builtin commands return exit codes, as does d631 1 a631 1 child of the invoking shell (unless it is a shell builtin, in which case d670 1 a670 1 .Dq true || echo bar && echo baz d721 1 a721 1 These are implemented as builtin commands. d746 1 a746 1 Builtin commands grouped into a (list) will not affect the current shell. d778 1 a778 1 Local is implemented as a builtin command. d781 1 a781 1 and readonly flags from the variable with the same name in the surrounding d802 1 a802 1 Return is implemented as a builtin command. d823 1 a823 1 builtin can also be used to set or reset them. d868 1 a868 1 invocation, by the set builtin command, or implicitly d1148 2 a1149 2 .Ss Builtins This section lists the builtin commands which are builtin because they d1153 1 a1153 1 be builtin for efficiency (e.g. d1177 1 a1177 1 builtin prints the d1193 1 a1193 1 have a shell function with the same name as a builtin command.) d1203 1 a1203 1 This is the same as the type builtin. d1207 1 a1207 1 of utilities, the name for builtins or the expansion of aliases. d1246 1 a1246 1 specified program (which must be a real program, not a shell builtin or d1285 1 a1285 1 builtin lists, or edits and re-executes, commands previously entered d1383 1 a1383 1 builtin may be used to obtain options and their arguments d1397 1 a1397 1 builtin will place it in the shell variable d1503 1 a1503 1 If d1510 1 a1510 1 .Xr getcwd(3) . d1518 1 a1518 1 but note that the builtin d1539 1 a1539 1 The builtin command may differ from the program of the same name because d1542 1 a1542 1 and the builtin uses a separately cached value. d1563 1 a1563 1 builtin will indicate success unless EOF is encountered on input, in d1605 1 a1605 1 positional parameters to the specified args. d1610 1 a1610 1 If no args are present, the set command d1667 1 a1667 1 On interractive shells, the d1701 1 a1701 1 shell keyword, alias, shell builtin, d1803 1 a1803 1 .Sx Builtins ) d1843 1 a1843 1 if the exit builtin is used with a numeric argument, it will return the d1853 1 a1853 1 cd builtin. d1859 1 a1859 1 The search path used with the cd builtin. @ 1.80 log @Whitespace and punctuation fixes. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.79 2005/05/07 19:52:17 dsl Exp $ d34 1 a34 1 .Dd May 7, 2005 d1663 1 a1663 1 The d1667 3 @ 1.79 log @If 'set -o tabcomplete' it set, then bind to the libedit filename completion function. Note that the libedit code will probably want fine-tuning! While editing the man page, add a note that non-whitespace IFS chars are terminators and can generate null arguments. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.78 2004/06/03 19:54:37 hubertf Exp $ d1078 1 a1078 1 None whitespace characters in d1081 1 a1081 1 So adjacent non whitespace d1087 1 a1087 1 is unset it is assumed to contain space, tab and newline. d1409 1 a1409 1 argument which may or may not be separated from it by white space. @ 1.78 log @Fix typo: and the -> and then @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.77 2004/04/23 13:28:15 wiz Exp $ d34 1 a34 1 .Dd April 17, 2004 d307 6 d954 1 a954 1 expansion, with the exception of @@. d1077 11 d1946 4 @ 1.77 log @Fix typo noted by Patrick Welche. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.76 2004/04/17 15:42:42 wiz Exp $ d1774 1 a1774 1 complete and the return an exit status of zero. @ 1.76 log @Bump date for previous. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.75 2004/04/17 15:41:29 christos Exp $ d783 1 a783 1 The only special parameter than can be made local is @ 1.75 log @understand rlimit sbsize @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.74 2003/12/21 11:16:23 wiz Exp $ d34 1 a34 1 .Dd December 21, 2003 @ 1.74 log @Fix example added in previous. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.73 2003/12/21 08:40:29 jdolecek Exp $ d1714 2 @ 1.73 log @add a note to Short-Circuit operators section about the somewhat nonintuitive evaluation in case there is both || and && specified pointed out in bin/23814 by VaX#n8 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.72 2003/12/18 15:52:31 heas Exp $ d665 4 a668 1 and nothing else. This is not the way it works in C. @ 1.72 log @correct 2 typos @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.71 2003/11/14 20:00:28 dsl Exp $ d34 1 a34 1 .Dd November 14, 2003 d663 3 @ 1.71 log @Posix requires that 'pwd -P' reset the shells saved cwd value - so a subsequent 'pwd -L' will report the same value. Update man page to be a closer match to reality. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.70 2003/10/27 08:23:40 wiz Exp $ d1192 1 a1192 1 the first occurance of d1731 1 a1731 1 show or set the limit on the number files a process can have open at once @ 1.70 log @passwd(5), not passwd(4). From Igor Sobrado in PR 23278. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.69 2003/10/27 08:22:21 wiz Exp $ d34 1 a34 1 .Dd February 12, 2003 d302 5 d1186 1 a1186 1 .It cd Op Ar directory d1189 8 a1196 1 If an entry for d1478 1 a1478 1 .It pwd d1480 13 a1492 5 The builtin command may differ from the program of the same name because the builtin command remembers what the current directory is rather than recomputing it each time. This makes it faster. However, if the current directory is renamed, the builtin version of d1494 26 a1519 1 will continue to print the old name for the directory. @ 1.69 log @Do not xref alias(1) since that points to csh(1). Noted by Igor Sobrado in PR 23278, fixed following a suggestion by Greg A. Woods. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.68 2003/08/07 09:05:37 agc Exp $ d1778 1 a1778 1 .Pq Xr passwd 4 . @ 1.68 log @Move UCB-licensed code from 4-clause to 3-clause licence. Patches provided by Joel Baker in PR 22249, verified by myself. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.67 2003/06/27 09:11:12 wiz Exp $ d359 1 a359 1 .Xr alias 1 @ 1.67 log @Quote some punctuation. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.66 2003/05/06 08:33:08 wiz Exp $ d16 1 a16 5 .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors @ 1.66 log @Drop trailing space. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.65 2003/05/04 01:05:24 gmcgarry Exp $ d850 1 a850 1 .It ? d860 1 a860 1 .It ! d1085 1 a1085 1 .Dq ! , d1087 1 a1087 1 .Dq ? , d1089 1 a1089 1 .Dq [ . d1384 1 a1384 1 .Dq ? ; d1403 1 a1403 1 .Dq ? . @ 1.65 log @Add new builtin 'inputrc' which allows keybindings to be redefined for the current shell. From Arne H Juul in PR#10097. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.64 2003/05/02 09:00:14 gmcgarry Exp $ d1744 1 a1744 1 section above.) d1862 1 a1864 1 .\" .Xr profile 4 , @ 1.64 log @Expand documentation of emacs and vi modes. From Jeremy C. Reed in PR#14578. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.63 2003/04/12 16:39:19 zuntum Exp $ d1457 5 d1862 1 a1863 1 .Xr editrc 5 , @ 1.63 log @add missing parenthesis @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.62 2003/03/22 11:37:49 kristerw Exp $ d292 3 d296 1 a296 2 Enable the built-in .Xr emacs 1 d300 3 d1730 4 a1733 3 can be edited using vi-mode command-line editing. This mode uses commands, described below, similar to a subset of those described in the vi man page. d1736 8 a1743 1 enables vi-mode editing and place sh into vi insert mode. a1745 1 The editor is not described in full here, but will be in a later document. d1752 10 d1855 1 d1858 1 @ 1.62 log @Change "if" to "if and only if" per discussion in PR 20794. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.61 2003/02/25 10:34:41 wiz Exp $ d432 1 a432 1 .Sq Bq 3 , @ 1.61 log @.Nm does not need a dummy argument ("") before punctuation or for correct formatting of the SYNOPSIS any longer. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.60 2003/02/12 19:00:08 wiz Exp $ d648 2 a649 2 executes the first command, and then executes the second command iff the exit status of the first command is zero. d651 2 a652 2 is similar, but executes the second command iff the exit status of the first command is nonzero. @ 1.60 log @New sentence, new line; bump date for last change. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.59 2003/02/12 02:55:14 gmcgarry Exp $ d45 1 a45 1 .Nm "" d57 1 a57 1 .Nm "" d71 1 a71 1 .Nm "" @ 1.59 log @Introduce LANG environment variable and Xref to nls(7). Comment out the statement: "We expect POSIX conformance by the time 4.4BSD is released." @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.58 2003/01/23 18:32:07 wiz Exp $ d38 1 a38 1 .Dd January 19, 2003 d1766 2 a1767 1 to work with different culture-specific and language conventions. See @ 1.58 log @Fix indentation of continuation of first line in SYNOPSIS. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.57 2003/01/22 22:05:45 wiz Exp $ d99 3 a101 3 We expect .Tn POSIX conformance by the time 4.4 BSD is released. d1764 4 d1836 1 @ 1.57 log @More markup, more commas, less typos. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.56 2003/01/22 20:36:04 dsl Exp $ d45 1 a45 1 .Nm @ 1.56 log @Support command -p, -v and -V as posix Stop temporary PATH assigments messing up hash table Fix sh -c -e "echo $0 $*" -a x (as posix) (agreed by christos) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.55 2002/12/28 05:08:27 uebayasi Exp $ d222 6 a227 4 Read commands from the command_string operand instead of from the standard input. Special parameter 0 will be set from the command_name operand and the positional parameters ($1, $2 etc) d553 1 a553 1 (if any) otherwise 0. d1173 2 a1174 1 command search. This is the same as the type builtin. d1793 1 a1793 1 Output before each line when execution trace (set -x) in enabled, d1843 1 a1843 1 PS1, PS2 and PS4 should be subject to parameter expansion before @ 1.55 log @trap '' SIGINT -> trap '' INT. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.54 2002/12/19 18:04:41 kleink Exp $ d38 1 a38 1 .Dd February 25, 2002 a45 2 .Op Fl /+aCefnuvxIimqsVEbc .Op Fl o Ar longname d47 36 a82 1 .Op Ar target ... d222 5 a226 2 Read commands from the command line. No commands will be read from the standard input. d548 4 d1152 9 a1160 2 .It command Ar command Ar arg ... Execute the specified builtin command. d1163 14 d1789 4 d1819 1 d1823 1 d1839 3 @ 1.54 log @Another it's -> its. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.53 2002/12/12 11:50:40 uebayasi Exp $ d1549 1 a1549 1 .Dl trap '' SIGINT QUIT tstp 30 @ 1.53 log @`` [n1]>&n2 Duplicate standard output (or n1) _TO_ n2.'' @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.52 2002/10/02 10:01:46 wiz Exp $ d1290 1 a1290 1 and it's index in the shell variable @ 1.52 log @filesystem -> file system, automaticly -> automatically. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.51 2002/10/01 15:06:31 wiz Exp $ d412 1 a412 1 Duplicate standard output (or n1) from n2. @ 1.51 log @Use more mdoc, particularly to get rid of some \*[Lt] and \*[Gt]. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.50 2002/09/25 15:18:42 wiz Exp $ d461 1 a461 1 command is searched for as a normal program in the filesystem (as d1688 1 a1688 1 Set automaticly by @ 1.50 log @New policy: New sentences start on a new line. Patches by Robert Elz , with minimal changes by me. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.49 2002/05/15 19:43:29 bjh21 Exp $ d52 2 a53 1 Sh is the standard command interpreter for the system. d332 1 a332 1 .Dl lf foobar \*[Lt]return\*[Gt] d336 1 a336 1 .Dl ls -F foobar \*[Lt]return\*[Gt] d533 2 a534 1 by the control operator |. The standard output of all but d570 3 a572 1 A ; or \*[Lt]newline\*[Gt] terminator causes the preceding AND-OR-list (described d671 3 a673 2 The pattern can actually be one or more patterns (see Shell Patterns described later), separated by d776 3 a778 1 variable, or by a \*[Lt]space\*[Gt] if d935 2 a936 1 In each case, pattern matching notation (see Shell Patterns), d982 5 a986 2 \*[Lt]newline\*[Gt]s at the end of the substitution. (Embedded \*[Lt]newline\*[Gt]s before d988 3 a990 1 they may be translated into \*[Lt]space\*[Gt]s, depending on the value of d1730 6 a1735 2 This is normally set to \*[Lt]space\*[Gt] \*[Lt]tab\*[Gt] and \*[Lt]newline\*[Gt]. See the @ 1.49 log @Implement sh -a (allexport). Code (all two lines of it) from FreeBSD (FreeBSD var.c 1.13, sh.1 1.27). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.48 2002/05/15 16:33:35 christos Exp $ d52 2 a53 2 Sh is the standard command interpreter for the system. The current version of d57 2 a58 1 1003.2 and 1003.2a specifications for the shell. This version has many d67 2 a68 1 conformance by the time 4.4 BSD is released. This man page is not intended d72 3 a74 3 terminal, interprets them, and generally executes other commands. It is the program that is running when a user logs into the system (although a user can select a different shell with the d76 2 a77 1 command). The shell implements a language that has flow control d80 2 a81 1 capabilities. It incorporates many features to aid interactive use and d83 2 a84 1 interactive and non-interactive use (shell scripts). That is, commands d94 5 a98 5 option is not present, the shell is considered an interactive shell. An interactive shell generally prompts before each command and handles programming and command errors differently (as described below). When first starting, the shell inspects argument 0, and if it begins with a dash d101 4 a104 2 a login shell. This is normally done automatically by the system when the user first logs in. A login shell first reads commands d122 2 a123 1 file. To set the d133 2 a134 1 any filename you wish. Since the d140 2 a141 1 file to interactive invocations. Place commands within the d163 2 a164 1 positional parameters of the shell ($1, $2, etc). Otherwise, the shell d170 2 a171 1 option. The set d174 2 a175 1 the description below. Specifying a dash d196 1 a196 2 explicitly tested if the command is used to control an d210 2 a211 2 If not interactive, read commands but do not execute them. This is useful for checking the syntax of shell scripts. d216 2 a217 2 The shell writes its input to standard error as it is read. Useful for debugging. d219 1 a219 2 Write each command to standard error (preceded by a d221 2 a222 1 before it is executed. Useful for debugging. d243 2 a244 1 are present). This option has no effect when set after the shell has d269 2 a270 1 operators (their meaning is discussed later). Following is a list of operators: d279 3 a281 3 words to the shell, such as operators, whitespace, or keywords. There are three types of quoting: matched single quotes, matched double quotes, and backslash. d308 2 a309 1 after a control operator. The following are reserved words: d320 2 a321 1 builtin command. Whenever a reserved word may occur (see above), d323 3 a325 3 checks the word to see if it matches an alias. If it does, it replaces it in the input stream with its value. For example, if there is an alias called d339 2 a340 2 They can also be used to create lexically obscure code. This use is discouraged. d346 2 a347 1 1003.2 document). Essentially though, a line is read and if the first d349 2 a350 1 then the shell has recognized a simple command. Otherwise, a complex d367 3 a369 2 command is located. The remaining words are considered the arguments of the command. If no command name resulted, then the d377 4 a380 2 its output. In general, redirections open, close, or duplicate an existing reference to a file. The overall format used for redirection is: d386 3 a388 2 is one of the redirection operators mentioned previously. Following is a list of the possible redirections. The d429 2 a430 1 it is specified. If the delimiter as specified on the initial line is d442 2 a443 2 normal programs -- and the command is searched for (by name) in that order. They each are executed in a different way. d447 2 a448 1 function. The variables which are explicitly placed in the environment of d450 5 a454 4 made local to the function and are set to the values given. Then the command given in the function definition is executed. The positional parameters are restored to their original values when the command completes. This all occurs within the current shell. d461 4 a464 3 described in the next section). When a normal program is executed, the shell runs the program, passing the arguments and the environment to the program. If the program is not a normal executable file (i.e., if it does d471 3 a473 2 then) the shell will interpret the program in a subshell. The child shell will reinitialize itself in this case, so that the effect will be as if a d483 2 a484 1 function by that name. Then it looks for a builtin command by that name. d493 2 a494 1 in turn for the command. The value of the d496 3 a498 2 variable should be a series of entries separated by colons. Each entry consists of a directory name. The current directory may be indicated d503 2 a504 1 of other shell commands. The paradigm is that a command exits d506 2 a507 1 error, or a false indication. The man page for each command d534 2 a535 1 of the next command. The standard output of the last d543 2 a544 1 command2. The standard input, standard output, or both of a command is d554 2 a555 1 last command. That is, if the last command returns zero, the exit status d560 2 a561 2 takes place before redirection, it can be modified by redirection. For example: d591 3 a593 2 characters. The commands in a list are executed in the order they are written. If command is followed by an ampersand, the shell starts the d630 2 a631 1 first list is zero. The until command is similar, but has the word d643 2 a644 1 variable set to each word in turn. do and done may be replaced with d680 5 a684 5 The first of these executes the commands in a subshell. Builtin commands grouped into a (list) will not affect the current shell. The second form does not fork another shell so is slightly more efficient. Grouping commands together this way allows you to redirect their output as though they were one program: d701 2 a702 2 installs a function named name and returns an exit status of zero. The command is normally a list enclosed between d708 2 a709 2 command. This should appear as the first statement of a function, and the syntax is d717 3 a719 2 scope, if there is one. Otherwise, the variable is initially unset. The shell uses dynamic scoping, so that if you make the variable x local to d736 2 a737 2 It terminates the currently executing function. Return is implemented as a builtin command. d739 5 a743 3 The shell maintains a set of parameters. A parameter denoted by a name is called a variable. When starting up, the shell turns all the environment variables into shell variables. New variables can be set using the form d749 2 a750 1 numeric. A parameter can also be denoted by a number or a special d753 4 a756 3 A positional parameter is a parameter denoted by a number (n \*[Gt] 0). The shell sets these initially to the values of its command line arguments that follow the name of the shell script. The d761 2 a762 1 characters. The value of the parameter is listed next to its character. d765 2 a766 1 Expands to the positional parameters, starting from one. When the d775 2 a776 2 Expands to the positional parameters, starting from one. When the expansion occurs within double-quotes, each positional d780 2 a781 1 double-quoted. What this basically means, for example, is d804 2 a805 2 Expands to the process ID of the invoked shell. A subshell retains the same value of $ as its parent. d808 2 a809 3 command executed from the current shell. For a pipeline, the process ID is that of the last command in the pipeline. d819 4 a822 2 single field. It is only field splitting or pathname expansion that can create multiple fields from a single word. The single exception to this d848 2 a849 1 subjected to tilde expansion. All the characters up to d851 2 a852 2 and are replaced with the user's home directory. If the username is missing (as in d881 1 a881 2 If a parameter expansion occurs inside double-quotes: d884 1 a884 2 Pathname expansion is not performed on the results of the expansion. d894 2 a895 1 Use Default Values. If parameter is unset or null, the expansion of word d898 5 a902 3 Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. In all cases, the final value of parameter is substituted. Only variables, not positional parameters or special d905 2 a906 1 Indicate Error if Null or Unset. If parameter is unset or null, the d908 3 a910 3 is written to standard error and the shell exits with a nonzero exit status. Otherwise, the value of parameter is substituted. An interactive shell need not exit. d912 2 a913 1 Use Alternative Value. If parameter is unset or null, null is d922 2 a923 2 String Length. The length in characters of the value of parameter. d927 2 a928 1 processing. In each case, pattern matching notation (see Shell Patterns), d936 3 a938 2 Remove Smallest Suffix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the d941 2 a942 1 Remove Largest Suffix Pattern. The word is expanded to produce a pattern. d946 3 a948 2 Remove Smallest Prefix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the d951 2 a952 1 Remove Largest Prefix Pattern. The word is expanded to produce a pattern. d958 2 a959 2 place of the command name itself. Command substitution occurs when the command is enclosed as follows: d974 2 a975 1 \*[Lt]newline\*[Gt]s at the end of the substitution. (Embedded \*[Lt]newline\*[Gt]s before d982 2 a983 2 expression and substituting its value. The format for arithmetic expansion is as follows: d988 2 a989 2 that a double-quote inside the expression is not treated specially. The shell expands all tokens in the expression for parameter expansion, d1008 3 a1010 2 complete. Each word is viewed as a series of patterns, separated by slashes. The process of expansion replaces the word with the names of all d1012 2 a1013 1 string that matches the specified pattern. There are two restrictions on d1016 2 a1017 1 first character of the pattern is a period. The next section describes the d1023 2 a1024 1 and meta-characters. The meta-characters are d1030 4 a1033 3 These characters lose their special meanings if they are quoted. When command or variable substitution is performed and the dollar sign or back quotes are not double quoted, the value of the variable or the output of d1039 3 a1041 2 matches any string of characters. A question mark matches any single character. A left bracket d1043 2 a1044 2 introduces a character class. The end of the character class is indicated by a d1052 4 a1055 3 rather than introducing a character class. A character class matches any of the characters between the square brackets. A range of characters may be specified using a minus sign. The character class may be complemented d1062 2 a1063 1 if any). To include a minus sign, make it the first or last character listed d1067 2 a1068 1 process. In addition to these, there are several other commands that may d1090 2 a1091 1 is printed. With no arguments, the d1100 2 a1101 1 Execute the specified builtin command. (This is useful when you d1115 2 a1116 1 will be searched for the specified directory. The format of d1124 2 a1125 1 that the user gave. These may be different either because the d1129 2 a1130 2 Concatenate all the arguments with spaces. Then re-parse and execute the command. d1134 2 a1135 1 function). Any redirections on the d1141 2 a1142 1 Terminate the shell process. If d1149 3 a1151 2 environment of subsequent commands. The only way to un-export a variable is to unset it. The shell allows the value of a variable to be set at the d1176 2 a1177 2 Use the editor named by editor to edit the commands. The editor string is a command name, subject to search via the d1179 2 a1180 1 variable. The value in the d1184 2 a1185 1 is not specified. If d1189 2 a1190 1 variable is used. If d1196 3 a1198 3 List the commands rather than invoking an editor on them. The commands are written in the sequence indicated by the first and last operands, as affected by d1214 2 a1215 1 Select the commands to list or edit. The number of previous commands that d1218 2 a1219 1 variable. The value of first or last or both are one of the following: d1228 2 a1229 2 number of commands previously. For example, -1 is the immediately previous command. d1233 2 a1234 1 that string. If the old=new operand is not also specified with d1259 2 a1260 1 argument. The variable specified is set to the parsed option. d1271 2 a1272 1 from a list of parameters. When invoked, d1281 2 a1282 1 is initialized to 1. For each option that requires an argument, the d1296 2 a1297 2 argument which may or may not be separated from it by white space. If an option character is not found where expected, d1306 2 a1307 2 and write output to standard error. By specifying a colon as the first character of d1354 2 a1355 1 locations of commands. With no arguments whatsoever, d1358 2 a1359 2 command prints out the contents of this table. Entries which have not been looked at since the last d1367 2 a1368 1 they are functions) and then locates them. With the d1370 2 a1371 1 option, hash prints the locations of the commands as it finds them. The d1384 2 a1385 2 Print the current directory. The builtin command may differ from the program of the same name because the d1387 3 a1389 3 is rather than recomputing it each time. This makes it faster. However, if the current directory is renamed, the builtin version of d1399 3 a1401 2 option is specified and the standard input is a terminal. Then a line is read from the standard input. The trailing newline is deleted from the d1403 3 a1405 3 above, and the pieces are assigned to the variables in order. If there are more pieces than variables, the remaining pieces (along with the characters in d1407 4 a1410 3 that separated them) are assigned to the last variable. If there are more variables than pieces, the remaining variables are assigned the null string. The d1420 2 a1421 1 literally. If a backslash is followed by a newline, the backslash and the d1426 2 a1427 1 subsequently modified or unset. The shell allows the value of a variable d1447 1 a1447 2 With no arguments, it lists the values of all shell variables. d1450 1 a1450 2 flags, or clears them as described in the section called d1454 2 a1455 1 positional parameters to the specified args. To change the positional d1458 2 a1459 1 as the first argument to set. If no args are present, the set command d1463 2 a1464 1 Assigns value to variable. (In general it is better to write d1472 2 a1473 1 Shift the positional parameters n times. A d1486 2 a1487 1 by one. If there are zero positional parameters, d1498 2 a1499 2 signals are received. The signals are specified by signal number or as the name of the signal. d1511 2 a1512 1 signals to the default action. The d1545 2 a1546 1 search. Possible resolutions are: d1548 2 a1549 1 command, tracked alias and not found. For aliases the alias expansion is d1557 2 a1558 1 limits. The choice between hard limit (which no process is allowed to d1566 2 a1567 1 set or inquire about soft limits. If neither d1571 2 a1572 2 is specified, the soft limit is displayed or both limits are set. If both are specified, the last one wins. d1607 2 a1608 1 or set. If value is specified, the limit is set to that number; otherwise d1618 2 a1619 2 to the specified octal value. If the argument is omitted, the umask value is printed. d1626 2 a1627 1 is specified, the shell removes that alias. If d1631 3 a1633 3 The specified variables and functions are unset and unexported. If a given name corresponds to both a variable and a function, both the variable and the function are unset. d1636 2 a1637 1 last process in the job. If the argument is omitted, wait for all jobs to d1648 4 a1651 3 can be edited using vi-mode command-line editing. This mode uses commands, described below, similar to a subset of those described in the vi man page. The command d1653 4 a1656 3 enables vi-mode editing and place sh into vi insert mode. With vi-mode enabled, sh can be switched between insert mode and command mode. The editor is not described in full here, but will be in a later document. d1659 2 a1660 1 will throw you into command VI command mode. Hitting d1665 4 a1668 2 shell to exit with a non-zero exit status. If the shell is not an interactive shell, the execution of the shell file will be aborted. Otherwise d1682 2 a1683 1 The default search path for executables. See the above section d1697 2 a1698 1 file. If set to 0, the check will occur at each prompt. d1705 2 a1706 1 setting. There is a maximum of 10 mailboxes that can be monitored at once. d1716 2 a1717 1 Input Field Separators. This is normally set to \*[Lt]space\*[Gt] \*[Lt]tab\*[Gt] and d1722 2 a1723 1 The default terminal setting for the shell. This is inherited by @ 1.48 log @implement noclobber. From Ben Harris, with minor tweaks from me. Two unimplemented comments to go. Go Ben! @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.47 2002/05/15 14:59:21 christos Exp $ d173 1 a173 1 Export all variables assigned to. (UNIMPLEMENTED for 4.4alpha) @ 1.47 log @Implement unset variable error messages from Ben Harris. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.46 2002/02/24 21:41:52 lukem Exp $ a179 1 (UNIMPLEMENTED for 4.4alpha) @ 1.46 log @first variable argument to "read" is not optional @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.45 2002/02/08 01:21:59 ross Exp $ a203 1 (UNIMPLEMENTED for 4.4alpha) @ 1.45 log @Generate <>& symbolically. I'm avoiding .../dist/... directories for now. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.44 2001/12/20 20:07:40 wiz Exp $ d38 1 a38 1 .Dd January 9, 1999 d1311 2 a1312 1 .Op Ar variable ... @ 1.44 log @Punctuation nits, drop unnecessary .Pps, sort sections. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.43 2001/04/03 10:56:03 wiz Exp $ d179 1 a179 1 .Dq > . d192 1 a192 1 .Dq && d261 1 a261 1 .Dl & && \&( \&) \&; ;; | || d263 1 a263 1 .Dl < > >| << >> <& >& <<- <> d291 1 a291 1 .Dl $ ` \*q \e . d317 1 a317 1 .Dl lf foobar d321 1 a321 1 .Dl ls -F foobar d376 1 a376 1 .It [n] Ns > file d378 1 a378 1 .It [n] Ns >| file d382 1 a382 1 .It [n] Ns >> file d384 1 a384 1 .It [n] Ns < file d386 1 a386 1 .It [n1] Ns <& Ns n2 d388 1 a388 1 .It [n] Ns <&- d390 1 a390 1 .It [n1] Ns >& Ns n2 d392 1 a392 1 .It [n] Ns >&- d394 1 a394 1 .It [n] Ns <> file d402 1 a402 1 .Li [n]<< delimiter d415 1 a415 1 .Dq <<- d417 1 a417 1 .Dq << , d530 1 a530 1 .Dl $ command1 2>&1 | command2 d535 2 a536 2 A ; or terminator causes the preceding AND-OR-list (described next) to be executed sequentially; a & causes asynchronous execution of d543 2 a544 2 .Ss Background Commands -- & If a command is terminated by the control operator ampersand (&), the d550 1 a550 1 .Dl command1 & [command2 & ...] d563 1 a563 1 .Dq && d567 1 a567 1 .Dq && d573 1 a573 1 .Dq && d651 1 a651 1 { echo -n \*q hello \*q ; echo \*q world" ; } > greeting d713 1 a713 1 A positional parameter is a parameter denoted by a number (n > 0). The d728 1 a728 1 variable, or by a if d920 1 a920 1 s at the end of the substitution. (Embedded s before d922 1 a922 1 they may be translated into s, depending on the value of d1607 1 a1607 1 .Dq > \ . d1609 2 a1610 2 Input Field Separators. This is normally set to and . See the @ 1.43 log @Don't xref set(1) and case(1), since they are builtins and we don't have separate man pages for them. Xref passwd 5 instead of 4, environ 7 instead of 5, and comment out xref to profile(4), which we don't have. Improve markup of SYNOPSIS. Some whitespace fixes while I'm here. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.42 2001/04/01 02:15:45 toddpw Exp $ d403 1 a403 1 .Dl here-doc-text... a456 1 .Pp a500 1 .Pp d602 1 a602 1 for variable in word... a658 1 .Pp a925 1 .Pp a1001 1 .Pp d1034 1 a1034 1 .It command Ar command Ar arg... d1060 1 a1060 1 .It eval Ar string... d1063 1 a1063 1 .It exec Op Ar command arg... d1076 1 a1076 1 .It export Ar name... d1272 1 a1272 1 .It hash Fl rv Ar command... d1311 1 a1311 1 .Op Ar variable... d1336 1 a1336 1 .It readonly Ar name... d1353 1 a1353 1 .Oc Ar arg... d1404 1 a1404 1 .Ar signal... d1532 1 a1532 1 .It unset Ar name... d1561 7 a1642 7 .Sh EXIT STATUS Errors that are detected by the shell, such as a syntax error, will cause the shell to exit with a non-zero exit status. If the shell is not an interactive shell, the execution of the shell file will be aborted. Otherwise the shell will return the exit status of the last command executed, or if the exit builtin is used with a numeric argument, it will return the argument. @ 1.42 log @Correct {list;} example and fix formatting/typo in the operator lists. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.41 2001/03/18 04:04:23 wulf Exp $ d42 2 a43 1 sh \- command interpreter (shell) d45 1 a45 1 .Nm sh d87 1 a87 1 and the d169 1 a169 1 .Xr set 1 d235 1 a235 1 .Xr set 1 ) . d719 1 a719 1 .Xr set 1 d965 1 a965 1 .Xr case 1 d1383 1 a1383 1 .Ic setvar d1428 1 a1428 1 ignored on entry to the shell. d1631 3 a1633 3 .Xr passwd 4 , .Xr profile 4 , .Xr environ 5 @ 1.41 log @Extended functionality of the trap builtin, which now closely follows POSIX recommendations. - trap now accepts signal names and signal numbers e.g. INT, SIGINT, 2 - added option -l that outputs a list of valid signals - added signal EXIT to list of valid signals - a `-' in the action part will reset specified signal to their default behaviour - changed standard output format to make it suitable as an input to another shell that achieves the same trapping results @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.40 2000/11/20 17:48:05 christos Exp $ d260 2 a261 2 .Dl & && ( ) ; ;; | || .It "Redirection operator:" d652 1 a652 1 { echo -n \*q hello \*q ; echo \*q world" } > greeting d654 6 @ 1.40 log @fix typo. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.39 2000/11/20 16:59:56 christos Exp $ d1398 3 d1405 3 a1407 1 signals are received. The signals are specified by signal number. If d1413 6 a1418 4 may be null or omitted; the former causes the specified signal to be ignored and the latter causes the default action to be taken. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The d1421 28 a1448 1 ignored on entry to the shell. @ 1.39 log @Add an example on how to use getopts, stolen from the getopt manual page :-) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.38 2000/09/21 21:04:56 phil Exp $ d1251 1 a1251 1 while getopts abo: c d1253 2 a1254 2 case $c in a | b) flag=$c;; @ 1.38 log @.Bl takes parameter "-offset indent", not "-indent". @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.37 2000/09/04 07:30:12 kleink Exp $ d1240 30 @ 1.37 log @For commands and utilities, use EXIT STATUS rather than RETURN VALUES as appropriate (and documented in mdoc(7)). @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.36 2000/08/28 02:11:06 hubertf Exp $ d338 1 a338 1 .Bl -enum -indent d374 1 a374 1 .Bl -tag -width aaabsfiles -indent @ 1.36 log @Add 'RETURN VALUE' section header. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.35 2000/07/18 01:55:48 jhawk Exp $ d1570 1 a1570 1 .Sh RETURN VALUES @ 1.35 log @Various mandoc updates to the Builtins section; mostly .Ic, a few other nits. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.34 2000/07/17 21:18:47 jhawk Exp $ d1570 1 a1570 1 .Sh DIAGNOSTICS @ 1.34 log @Note the meaning of 'trap 0' (execute on exit from shell) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.33 1999/11/16 22:03:25 hubertf Exp $ d1014 4 a1017 3 If name=string is specified, the shell defines the alias .Dq name d1019 1 a1019 1 .Dq string . d1021 1 a1021 1 .Dq name d1023 6 a1028 3 .Dq name is printed. With no arguments, the alias builtin prints the names and values of all defined aliases (see unalias). d1038 1 a1038 1 If the an entry for d1040 3 a1042 1 appears in the environment of the cd command or the shell variable d1051 3 a1053 1 In an interactive shell, the cd command will print out the name of the d1064 5 a1068 2 function). Any redirections on the exec command are marked as permanent, so that they are not undone when the exec command finishes. d1070 4 a1073 3 Terminate the shell process. If exitstatus is given it is used as the exit status of the shell; otherwise the exit status of the preceding command is used. d1097 4 a1100 2 The fc builtin lists, or edits and re-executes, commands previously entered to an interactive shell. d1243 12 a1254 7 the hash command prints out the contents of this table. Entries which have not been looked at since the last cd command are marked with an asterisk; it is possible for these entries to be invalid. .Pp With arguments, the hash command removes the specified commands from the hash table (unless they are functions) and then locates them. With the d1262 3 a1264 1 If the job argument is omitted, use the current job. d1274 3 a1276 2 renamed, the builtin version of pwd will continue to print the old name for the directory. d1292 4 a1295 3 string. The 'read' builtin will indicate success unless EOF is encountered on input, in which case failure is returned. d1323 3 a1325 1 The set command performs three different functions. d1344 4 a1347 1 variable=value rather than using setvar. Setvar is intended to be used in d1351 16 a1366 4 Shift the positional parameters n times. A shift sets the value of $1 to the value of $2, the value of $2 to the value of $3, and so on, decreasing the value of $# by one. If there are zero positional parameters, shifting doesn't do anything. d1387 2 a1388 1 search. Possible resolutions are: shell keyword, alias, shell builtin, @ 1.33 log @Add under which conditions the "read" builtin returns success/failure. Suggested in PR 8813 by Eric Mumpower @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.32 1999/09/28 14:54:43 bouyer Exp $ d1332 6 a1337 1 signals are received. The signals are specified by signal number. Action d1341 3 a1343 1 the default action. The trap command has no effect on signals that were @ 1.33.4.1 log @Pullup revs 1.34, 1.35, approved by jhawk. rev 1.34: Note the meaning of 'trap 0' (execute on exit from shell) rev 1.35: Various mandoc updates to the Builtins section; mostly .Ic, a few other nits. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.35 2000/07/18 01:55:48 jhawk Exp $ d1014 3 a1016 4 If .Ar name=string is specified, the shell defines the alias .Ar name d1018 1 a1018 1 .Ar string . d1020 1 a1020 1 .Ar name d1022 3 a1024 6 .Ar name is printed. With no arguments, the .Ic alias builtin prints the names and values of all defined aliases (see .Ic unalias ) . d1034 1 a1034 1 If an entry for d1036 1 a1036 3 appears in the environment of the .Ic cd command or the shell variable d1045 1 a1045 3 In an interactive shell, the .Ic cd command will print out the name of the d1056 2 a1057 5 function). Any redirections on the .Ic exec command are marked as permanent, so that they are not undone when the .Ic exec command finishes. d1059 3 a1061 4 Terminate the shell process. If .Ar exitstatus is given it is used as the exit status of the shell; otherwise the exit status of the preceding command is used. d1085 2 a1086 4 The .Ic fc builtin lists, or edits and re-executes, commands previously entered to an interactive shell. d1229 7 a1235 12 the .Ic hash command prints out the contents of this table. Entries which have not been looked at since the last .Ic cd command are marked with an asterisk; it is possible for these entries to be invalid. .Pp With arguments, the .Ic hash command removes the specified commands from the hash table (unless they are functions) and then locates them. With the d1243 1 a1243 3 If the .Ar job argument is omitted, the current job is used. d1253 2 a1254 3 renamed, the builtin version of .Ic pwd will continue to print the old name for the directory. d1270 3 a1272 4 string. The .Ic read builtin will indicate success unless EOF is encountered on input, in which case failure is returned. d1300 1 a1300 3 The .Ic set command performs three different functions. d1319 1 a1319 4 variable=value rather than using .Ic setvar . .Ic setvar is intended to be used in d1323 4 a1326 16 Shift the positional parameters n times. A .Ic shift sets the value of .Va $1 to the value of .Va $2 , the value of .Va $2 to the value of .Va $3 , and so on, decreasing the value of .Va $# by one. If there are zero positional parameters, .Ic shift does nothing. d1332 1 a1332 6 signals are received. The signals are specified by signal number. If .Ar signal is .Li 0 , the action is executed when the shell exits. .Ar action d1336 1 a1336 3 the default action. The .Ic trap command has no effect on signals that were d1340 1 a1340 2 search. Possible resolutions are: shell keyword, alias, shell builtin, @ 1.33.4.2 log @Pull up to netbsd-1-5 branch, OK'd by thorpej: Log Message: > Add 'RETURN VALUE' section header. Files & Revisionis: > cvs rdiff -r1.19 -r1.20 basesrc/bin/cat/cat.1 > cvs rdiff -r1.12 -r1.13 basesrc/bin/chmod/chmod.1 > cvs rdiff -r1.14 -r1.15 basesrc/bin/cp/cp.1 > cvs rdiff -r1.8 -r1.9 basesrc/bin/dd/dd.1 > cvs rdiff -r1.9 -r1.10 basesrc/bin/echo/echo.1 > cvs rdiff -r1.11 -r1.12 basesrc/bin/expr/expr.1 > cvs rdiff -r1.25 -r1.26 basesrc/bin/ls/ls.1 > cvs rdiff -r1.10 -r1.11 basesrc/bin/mkdir/mkdir.1 > cvs rdiff -r1.23 -r1.24 basesrc/bin/mt/mt.1 > cvs rdiff -r1.12 -r1.13 basesrc/bin/mv/mv.1 > cvs rdiff -r1.16 -r1.17 basesrc/bin/pwd/pwd.1 > cvs rdiff -r1.9 -r1.10 basesrc/bin/rm/rm.1 > cvs rdiff -r1.11 -r1.12 basesrc/bin/rmdir/rmdir.1 > cvs rdiff -r1.35 -r1.36 basesrc/bin/sh/sh.1 > cvs rdiff -r1.11 -r1.12 basesrc/bin/sleep/sleep.1 > cvs rdiff -r1.20 -r1.21 basesrc/bin/stty/stty.1 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.36 2000/08/28 02:11:06 hubertf Exp $ d1570 1 a1570 1 .Sh RETURN VALUES @ 1.33.4.3 log @.Bl argument is "-offset indent", not "-indent" (Approved thropej.) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.38 2000/09/21 21:04:56 phil Exp $ d338 1 a338 1 .Bl -enum -offset indent d374 1 a374 1 .Bl -tag -width aaabsfiles -offset indent d1570 1 a1570 1 .Sh EXIT STATUS @ 1.33.4.4 log @Extended functionality of the trap builtin, which now closely follows POSIX recommendations. - trap now accepts signal names and signal numbers e.g. INT, SIGINT, 2 - added option -l that outputs a list of valid signals - added signal EXIT to list of valid signals - a `-' in the action part will reset specified signal to their default behaviour - changed standard output format to make it suitable as an input to another shell that achieves the same trapping results @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.33.4.3 2000/09/21 21:32:35 phil Exp $ a1367 3 .Op Fl l .Xc .It Xo trap d1372 1 a1372 3 signals are received. The signals are specified by signal number or as the name of the signal. If d1378 4 a1381 6 may be null, which cause the specified signals to be ignored. With .Ar action omitted or set to `-' the specified signals are set to their default action. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The d1384 1 a1384 28 ignored on entry to the shell. Issuing .Ic trap with option .Ar -l will print a list of valid signal names. .Ic trap without any arguments cause it to write a list of signals and their associated action to the standard output in a format that is suitable as an input to the shell that achieves the same trapping results. .Pp Examples: .Pp .Dl trap .Pp List trapped signals and their corresponding action .Pp .Dl trap -l .Pp Print a list of valid signals .Pp .Dl trap '' SIGINT QUIT tstp 30 .Pp Ignore signals INT QUIT TSTP USR1 .Pp .Dl trap date INT .Pp Print date upon receiving signal INT @ 1.33.4.5 log @Reversed submission of trap.c and sh.1 to wrong branch @ text @d1368 3 d1375 3 a1377 1 signals are received. The signals are specified by signal number. If d1383 6 a1388 4 may be null or omitted; the former causes the specified signal to be ignored and the latter causes the default action to be taken. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The d1391 28 a1418 1 ignored on entry to the shell. @ 1.33.4.6 log @Pull up revision 1.43 (via patch, requested by wiz): Don't xref set(1) and case(1), since they are builtins and we don't have separate man pages for them. Xref passwd 5 instead of 4, environ 7 instead of 5, and comment out xref to profile(4), which we don't have. Improve markup of SYNOPSIS. Some whitespace fixes while I'm here. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.33.4.5 2001/03/18 03:20:12 wulf Exp $ d42 2 a44 3 .Nd command interpreter (shell) .Sh SYNOPSIS .Nm d86 1 a86 1 and the d168 1 a168 1 .Ic set d234 1 a234 1 .Ic set ) . d712 1 a712 1 .Ic set d958 1 a958 1 .Ic case d1346 1 a1346 1 .Ic setvar d1560 3 a1562 3 .Xr passwd 5 , .\" .Xr profile 4 , .Xr environ 7 , @ 1.33.4.7 log @Pull up revision 1.41 (requested by jonb): Extend functionality of the trap builtin, which now more closely follows POSIX recommendations: o accept signal names as well as signal numbers o add ``-l'' option which outputs list of valid signals o add signal EXIT to list of valid signals o an ``-'' in the action part will reset signal to default behaviour o changed standard output of ``trap'' to make it suitable as subsequent input @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.33.4.6 2001/04/04 16:15:24 he Exp $ a1368 3 .Op Fl l .Xc .It Xo trap d1373 1 a1373 3 signals are received. The signals are specified by signal number or as the name of the signal. If d1379 4 a1382 6 may be null, which cause the specified signals to be ignored. With .Ar action omitted or set to `-' the specified signals are set to their default action. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The d1385 1 a1385 28 ignored on entry to the shell. Issuing .Ic trap with option .Ar -l will print a list of valid signal names. .Ic trap without any arguments cause it to write a list of signals and their associated action to the standard output in a format that is suitable as an input to the shell that achieves the same trapping results. .Pp Examples: .Pp .Dl trap .Pp List trapped signals and their corresponding action .Pp .Dl trap -l .Pp Print a list of valid signals .Pp .Dl trap '' SIGINT QUIT tstp 30 .Pp Ignore signals INT QUIT TSTP USR1 .Pp .Dl trap date INT .Pp Print date upon receiving signal INT @ 1.32 log @xref sysctl(8) (for proc..rlimits) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.31 1999/09/27 19:34:25 mjl Exp $ d1271 2 @ 1.31 log @Mention -c option to sh(1), noticed by Matthew Aldous in PR/8499. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.30 1999/07/06 14:01:01 christos Exp $ d1398 4 d1513 1 @ 1.30 log @add -q in the synopsis line @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.29 1999/03/23 02:29:29 ross Exp $ d45 1 a45 1 .Op Fl /+aCefnuvxIimqsVEb d85 4 a88 1 flag is set), the shell is considered an interactive shell. An d173 3 @ 1.30.2.1 log @Pull up to last week's -current. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.33 1999/11/16 22:03:25 hubertf Exp $ d45 1 a45 1 .Op Fl /+aCefnuvxIimqsVEbc d85 1 a85 4 flag is set), and the .Fl c option is not present, the shell is considered an interactive shell. An a169 3 .It Fl c Read commands from the command line. No commands will be read from the standard input. a1264 2 The 'read' builtin will indicate success unless EOF is encountered on input, in which case failure is returned. a1391 4 Limits of an arbitrary process can be displayed or set using the .Xr sysctl 8 utility. .Pp a1502 1 .Xr sysctl 8 @ 1.29 log @Make the `...' actually appear in the case/esac syntax section. Fix a space botch in the $@@ example. Kill warnings caused by the effective but wrong use of \[ and \] to perform the function of \&[ and \&]. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.28 1999/02/04 00:27:07 cjs Exp $ d45 1 a45 1 .Op Fl /+aCefnuvxIimsVEb @ 1.28 log @Add -q option, which when used with -v and/or -x, turns off the tracing during the execution of /etc/profile, .profile and $ENV. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.27 1999/01/28 18:11:50 kleink Exp $ d622 1 a622 1 ... d738 1 a738 1 .Dl \*q abc \*q \ \*q def ghi \*q d972 1 a972 1 .Pq Dq [ d975 1 a975 1 .Pq Dq \] ; d977 1 a977 1 .Dq \] d979 1 a979 1 .Dq [ d981 1 a981 1 .Dq [ d988 1 a988 1 .Dq \] d990 1 a990 1 .Dq ! , d1462 1 a1462 1 .Dq \: @ 1.27 log @Add support for the export and readonly -p option. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.26 1999/01/11 19:34:53 garbled Exp $ d206 12 @ 1.26 log @Massive fixup: Rewrite man page in mandoc format rather than nasty man format. Fix a ton of parsing errors, and generate proper .Xr's. document all known environment variables. suggest ksh rather than bash. The last two fix PR #1966. Wheee! Somebody with access to the POSIX spec needs to go in here, and document our adherence, or lack thereof. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.25 1998/11/17 14:16:32 msaitoh Exp $ d1045 1 d1054 3 d1262 1 d1271 4 @ 1.25 log @fix some bugs @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.24 1998/10/29 23:23:36 garbled Exp $ d38 4 a41 3 .na .TH SH 1 .SH NAME d43 39 a81 38 .SH SYNOPSIS sh [-/+aCefnuvxIimsVEb] [-/+o longname] [arg ...] .SH DESCRIPTION .LP Sh is the standard command interpreter for the system. The current version of sh is in the process of being changed to conform with the POSIX 1003.2 and 1003.2a specifications for the shell. This version has many features which make it appear similar in some respects to the Korn shell, but it is not a Korn shell clone (run GNU's bash if you want that). Only features designated by POSIX, plus a few Berkeley extensions, are being incorporated into this shell. We expect POSIX conformance by the time 4.4 BSD is released. This man page is not intended to be a tutorial or a complete specification of the shell. .sp 2 .B Overview .sp .LP The shell is a command that reads lines from either a file or the terminal, interprets them, and generally executes other commands. It is the program that is running when a user logs into the system (although a user can select a different shell with the chsh(1) command). The shell implements a language that has flow control constructs, a macro facility that provides a variety of features in addition to data storage, along with built in history and line editing capabilities. It incorporates many features to aid interactive use and has the advantage that the interpretative language is common to both interactive and non-interactive use (shell scripts). That is, commands can be typed directly to the running shell or can be put into a file and the file can be executed directly by the shell. .sp 2 .B Invocation .sp .LP d83 9 a91 6 is connected to a terminal (or if the -i flag is set), the shell is considered an interactive shell. An interactive shell generally prompts before each command and handles programming and command errors differently (as described below). When first starting, the shell inspects argument 0, and if it begins with a dash '-', the shell is also considered d94 68 a161 44 from the files /etc/profile and .profile if they exist. If the environment variable ENV is set on entry to a shell, or is set in the .profile of a login shell, the shell next reads commands from the file named in ENV. Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every shell inside the ENV file. To set the ENV variable to some file, place the following line in your .profile of your home directory .nf ENV=$HOME/.shinit; export ENV .fi substituting for ``.shinit'' any filename you wish. Since the ENV file is read for every invocation of the shell, including shell scripts and non-interactive shells, the following paradigm is useful for restricting commands in the ENV file to interactive invocations. Place commands within the ``case'' and ``esac'' below (these commands are described later): .nf case $- in *i*) # commands for interactive use only ... esac .fi If command line arguments besides the options have been specified, then the shell treats the first argument as the name of a file from which to read commands (a shell script), and the remaining arguments are set as the positional parameters of the shell ($1, $2, etc). Otherwise, the shell reads commands from its standard input. .sp 2 .B Argument List Processing .sp .LP All of the single letter options have a corresponding name that can be used as an argument to the '-o' option. The set -o name is provided next to the single letter option in the description below. Specifying a dash ``-'' turns the option on, while using a plus ``+'' d164 9 a172 8 with the set(1) builtin (described later). .TP -a allexport Export all variables assigned to. (UNIMPLEMENTED for 4.4alpha) .TP -C noclobber Don't overwrite existing files with ``>''. d174 2 a175 4 .TP -e errexit If not interactive, exit immediately if any untested command fails. d178 12 a189 5 an if, elif, while, or until; or if the command is the left hand operand of an ``&&'' or ``||'' operator. .TP -f noglob d191 6 a196 10 .TP -n noexec If not interactive, read commands but do not execute them. This is useful for checking the syntax of shell scripts. .TP -u nounset Write a message to standard error when attempting to expand a variable that is not set, and if the shell is not interactive, exit immediately. d198 4 a201 6 .TP -v verbose The shell writes its input to standard error as it is read. Useful for debugging. .TP -x xtrace d203 4 a206 4 by a '+ ') before it is executed. Useful for debugging. .TP -I ignoreeof d208 1 a208 2 .TP -i interactive d210 21 a230 22 .TP -m monitor Turn on job control (set automatically when interactive). .TP -s stdin Read commands from standard input (set automatically if no file arguments are present). This option has no effect when set after the shell has already started running (i.e. with set(1)). .TP -V vi Enable the built-in vi(1) command line editor (disables -E if it has been set). .TP -E emacs Enable the built-in emacs(1) command line editor (disables -V if it has been set). .TP -b notify Enable asynchronous notification of background job completion. d232 20 a251 31 .LP .sp 2 .B Lexical Structure .sp .LP The shell reads input in terms of lines from a file and breaks it up into words at whitespace (blanks and tabs), and at certain sequences of characters that are special to the shell called ``operators''. There are two types of operators: control operators and redirection operators (their meaning is discussed later). Following is a list of operators: .nf .sp Control operators: & && ( ) ; ;; | || .sp Redirection operator: < > >| << >> <& >& <<- <> .sp .fi .sp 2 .B Quoting .sp .LP Quoting is used to remove the special meaning of certain characters or words to the shell, such as operators, whitespace, or keywords. There are three types of quoting: matched single quotes, matched double quotes, and backslash. .sp 2 .B Backslash .sp .LP d253 10 a262 13 character, with the exception of . A backslash preceding a is treated as a line continuation. .sp 2 .B Single Quotes .sp .LP Enclosing characters in single quotes preserves the literal meaning of all the characters (except single quotes, making it impossible to put single-quotes in a single-quoted string). .sp 2 .B Double Quotes .sp .LP d264 9 a272 4 meaning of all characters except dollarsign ($), backquote (`), and backslash (\\). The backslash inside double quotes is historically weird, and serves to quote only the following characters: $ ` " \\ . d274 1 a274 4 .sp 2 .B Reserved Words .sp .LP d278 6 a283 7 .nf ! elif fi while case else for then { } do done until if esac .fi d285 3 a287 5 .sp 2 .B Aliases .sp .LP An alias is a name and corresponding value set using the alias(1) d292 26 a317 32 if there is an alias called ``lf'' with the value ``ls -F'', then the input .nf lf foobar would become ls -F foobar .fi .LP Aliases provide a convenient way for naive users to create shorthands for commands without having to learn how to create functions with arguments. They can also be used to create lexically obscure code. This use is discouraged. .sp 2 .B Commands .sp .LP The shell interprets the words it reads according to a language, the specification of which is outside the scope of this man page (refer to the BNF in the POSIX 1003.2 document). Essentially though, a line is read and if the first word of the line (or after a control operator) is not a reserved word, then the shell has recognized a simple command. Otherwise, a complex command or some other special construct may have been recognized. .sp 2 .B Simple Commands .sp .LP d320 38 a357 37 .sp 1) Leading words of the form ``name=value'' are stripped off and assigned to the environment of the simple command. Redirection operators and their arguments (as described below) are stripped off and saved for processing. .sp 2) The remaining words are expanded as described in the section called ``Expansions'', and the first remaining word is considered the command name and the command is located. The remaining words are considered the arguments of the command. If no command name resulted, then the ``name=value'' variable assignments recognized in 1) affect the current shell. .sp 3) Redirections are performed as described in the next section. .sp 2 .B Redirections .sp .LP Redirections are used to change where a command reads its input or sends its output. In general, redirections open, close, or duplicate an existing reference to a file. The overall format used for redirection is: .nf [n] redir-op file .fi where redir-op is one of the redirection operators mentioned previously. Following is a list of the possible redirections. The [n] is an optional number, as in '3' (not '[3]'), that refers to a file descriptor. .TP [n]> file d359 5 a363 5 .TP [n]>| file Same, but override the -C option. .TP [n]>> file d365 1 a365 2 .TP [n]< file d367 3 a369 6 .TP [n1]<&n2 Duplicate standard input (or n1) from file descriptor n2. .TP [n]<&- d371 1 a371 2 .TP [n1]>&n2 d373 1 a373 2 .TP [n]>&- d375 81 a455 87 .TP [n]<> file Open file for reading and writing on standard input (or n). .LP The following redirection is often called a ``here-document''. .nf [n]<< delimiter here-doc-text... delimiter .fi All the text on successive lines up to the delimiter is saved away and made available to the command on standard input, or file descriptor n if it is specified. If the delimiter as specified on the initial line is quoted, then the here-doc-text is treated literally, otherwise the text is subjected to parameter expansion, command substitution, and arithmetic expansion (as described in the section on ``Expansions''). If the operator is ``<<-'' instead of ``<<'', then leading tabs in the here-doc-text are stripped. .sp 2 .B Search and Execution .sp .LP There are three types of commands: shell functions, builtin commands, and normal programs -- and the command is searched for (by name) in that order. They each are executed in a different way. .LP When a shell function is executed, all of the shell positional parameters (except $0, which remains unchanged) are set to the arguments of the shell function. The variables which are explicitly placed in the environment of the command (by placing assignments to them before the function name) are made local to the function and are set to the values given. Then the command given in the function definition is executed. The positional parameters are restored to their original values when the command completes. This all occurs within the current shell. .LP Shell builtins are executed internally to the shell, without spawning a new process. .LP Otherwise, if the command name doesn't match a function or builtin, the command is searched for as a normal program in the filesystem (as described in the next section). When a normal program is executed, the shell runs the program, passing the arguments and the environment to the program. If the program is not a normal executable file (i.e., if it does not begin with the "magic number" whose ASCII representation is "#!", so execve(2) returns ENOEXEC then) the shell will interpret the program in a subshell. The child shell will reinitialize itself in this case, so that the effect will be as if a new shell had been invoked to handle the ad-hoc shell script, except that the location of hashed commands located in the parent shell will be remembered by the child. .LP Note that previous versions of this document and the source code itself misleadingly and sporadically refer to a shell script without a magic number as a "shell procedure". .sp 2 .B Path Search .sp .LP When locating a command, the shell first looks to see if it has a shell function by that name. Then it looks for a builtin command by that name. If a builtin command is not found, one of two things happen: .sp 1) Command names containing a slash are simply executed without performing any searches. .sp 2) The shell searches each entry in PATH in turn for the command. The value of the PATH variable should be a series of entries separated by colons. Each entry consists of a directory name. The current directory may be indicated implicitly by an empty directory name, or explicitly by a single period. .sp 2 .B Command Exit Status .sp .LP d463 21 a483 27 .sp 2 .B Complex Commands .sp .LP Complex commands are combinations of simple commands with control operators or reserved words, together creating a larger complex command. More generally, a command is one of the following: .nf - simple command - pipeline - list or compound-list - compound command - function definition .fi .LP Unless otherwise stated, the exit status of a command is that of the last simple command executed by the command. .sp 2 .B Pipelines .sp .LP d489 1 a489 1 .LP d491 24 a514 31 .nf [!] command1 [ | command2 ...] .fi .LP The standard output of command1 is connected to the standard input of command2. The standard input, standard output, or both of a command is considered to be assigned by the pipeline before any redirection specified by redirection operators that are part of the command. .LP If the pipeline is not in the background (discussed later), the shell waits for all commands to complete. .LP If the reserved word ! does not precede the pipeline, the exit status is the exit status of the last command specified in the pipeline. Otherwise, the exit status is the logical NOT of the exit status of the last command. That is, if the last command returns zero, the exit status is 1; if the last command returns greater than zero, the exit status is zero. .LP Because pipeline assignment of standard input or standard output or both takes place before redirection, it can be modified by redirection. For example: .nf $ command1 2>&1 | command2 .fi d517 8 a524 9 .LP A ; or terminator causes the preceding AND-OR-list (described next) to be executed sequentially; a & causes asynchronous execution of the preceding AND-OR-list. .LP Note that unlike some other shells, each process in the pipeline is a child of the invoking shell (unless it is a shell builtin, in which case it executes in the current shell -- but any effect it has on the d526 5 a530 9 .sp 2 .B Background Commands -- & .sp .LP If a command is terminated by the control operator ampersand (&), the shell executes the command asynchronously -- that is, the shell does not wait for the command to finish before executing the next command. .LP d532 27 a558 29 .nf command1 & [command2 & ...] .fi If the shell is not interactive, the standard input of an asynchronous command is set to /dev/null. .sp 2 .B Lists -- Generally Speaking .sp .LP A list is a sequence of zero or more commands separated by newlines, semicolons, or ampersands, and optionally terminated by one of these three characters. The commands in a list are executed in the order they are written. If command is followed by an ampersand, the shell starts the command and immediately proceed onto the next command; otherwise it waits for the command to terminate before proceeding to the next one. .sp 2 .B Short-Circuit List Operators .sp .LP ``&&'' and ``||'' are AND-OR list operators. ``&&'' executes the first command, and then executes the second command iff the exit status of the first command is zero. ``||'' is similar, but executes the second command iff the exit status of the first command is nonzero. ``&&'' and ``||'' d560 1 a560 4 .sp 2 .B Flow-Control Constructs -- if, while, for, case .sp .LP d562 9 a570 10 .nf if list then list [ elif list then list ] ... [ else list ] fi .fi d572 6 a577 7 .nf while list do list done .fi d582 1 a582 1 .LP d584 12 a595 11 .nf for variable in word... do list done .fi The words are expanded, and then the list is executed repeatedly with the variable set to each word in turn. do and done may be replaced with ``{'' and ``}''. .LP d597 5 a601 6 .nf break [ num ] continue [ num ] .fi d605 1 a605 1 .LP d607 7 a613 9 .nf case word in pattern) list ;; ... esac .fi .LP d615 4 a618 5 Patterns described later), separated by ``|'' characters. .sp 2 .B Grouping Commands Together .sp .LP d620 3 a622 5 .nf (list) .fi d624 14 a637 21 .nf { list; } .fi The first of these executes the commands in a subshell. Builtin commands grouped into a (list) will not affect the current shell. The second form does not fork another shell so is slightly more efficient. Grouping commands together this way allows you to redirect their output as though they were one program: .nf { echo -n "hello"; echo " world" } > greeting .fi .sp 2 .B Functions .sp .LP d639 16 a654 19 .nf name ( ) command .fi .LP A function definition is an executable statement; when executed it installs a function named name and returns an exit status of zero. The command is normally a list enclosed between ``{'' and ``}''. .LP Variables may be declared to be local to a function by using a local command. This should appear as the first statement of a function, and the syntax is .nf local [ variable | - ] ... .fi d656 9 a664 11 .LP When a variable is made local, it inherits the initial value and exported and readonly flags from the variable with the same name in the surrounding scope, if there is one. Otherwise, the variable is initially unset. The shell uses dynamic scoping, so that if you make the variable x local to function f, which then calls function g, references to the variable x made inside g will refer to the variable x declared inside f, not to the global variable named x. .LP d666 5 a670 3 ``-''. Making ``-'' local any shell options that are changed via the set command inside the function to be restored to their original values when the function d672 1 a672 1 .LP d674 3 a676 5 .nf return [ exitstatus ] .fi d679 31 a709 42 .sp 2 .B Variables and Parameters .sp .LP The shell maintains a set of parameters. A parameter denoted by a name is called a variable. When starting up, the shell turns all the environment variables into shell variables. New variables can be set using the form .nf name=value .fi .LP Variables set by the user must have a name consisting solely of alphabetics, numerics, and underscores - the first of which must not be numeric. A parameter can also be denoted by a number or a special character as explained below. .sp 2 .B Positional Parameters .sp .LP A positional parameter is a parameter denoted by a number (n > 0). The shell sets these initially to the values of its command line arguments that follow the name of the shell script. The set(1) builtin can also be used to set or reset them. .sp 2 .B Special Parameters .sp .LP A special parameter is a parameter denoted by one of the following special characters. The value of the parameter is listed next to its character. .TP * Expands to the positional parameters, starting from one. When the expansion occurs within a double-quoted string it expands to a single field with the value of each parameter separated by the first character of the IFS variable, or by a if IFS is unset. .TP @@ d716 7 a722 1 if $1 is ``abc'' and $2 is ``def ghi'', then "$@@" expands to d724 5 a728 4 "abc" "def ghi" .TP # d730 1 a730 2 .TP ? d732 1 a732 2 .TP - (Hyphen) d737 1 a737 2 .TP $ d740 1 a740 2 .TP ! d745 1 a745 2 .TP 0 (Zero.) d747 12 a758 17 .LP .sp 2 .B Word Expansions .sp .LP This clause describes the various expansions that are performed on words. Not all expansions are performed on every word, as explained later. .LP Tilde expansions, parameter expansions, command substitutions, arithmetic expansions, and quote removals that occur within a single word expand to a single field. It is only field splitting or pathname expansion that can create multiple fields from a single word. The single exception to this rule is the expansion of the special parameter @@ within double-quotes, as was described above. .LP d760 3 a762 2 .LP (1) Tilde Expansion, Parameter Expansion, Command Substitution, d764 13 a776 8 .LP (2) Field Splitting is performed on fields generated by step (1) unless the IFS variable is null. .LP (3) Pathname Expansion (unless set -f is in effect). .LP (4) Quote Removal. .LP d779 1 a779 4 .sp 2 .B Tilde Expansion (substituting a user's home directory) .sp .LP d784 6 a789 8 username is missing (as in ~/foobar), the tilde is replaced with the value of the HOME variable (the current user's home directory). .sp 2 .B Parameter Expansion .sp .LP d791 7 a797 6 .nf ${expression} .fi where expression consists of all characters until the matching }. Any } d800 3 a802 2 expansions, are not examined in determining the matching }. .LP d804 3 a806 5 .nf ${parameter} .fi d808 1 a808 1 .LP d815 3 a817 2 .LP 1) Pathname expansion is not performed on the results of the d819 2 a820 2 .LP 2) Field splitting is not performed on the results of the d822 2 a823 1 .LP d826 20 a845 33 .sp .TP ${parameter:-word} Use Default Values. If parameter is unset or null, the expansion of word is substituted; otherwise, the value of parameter is substituted. .TP ${parameter:=word} Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. In all cases, the final value of parameter is substituted. Only variables, not positional parameters or special parameters, can be assigned in this way. .TP ${parameter:?[word]} Indicate Error if Null or Unset. If parameter is unset or null, the expansion of word (or a message indicating it is unset if word is omitted) is written to standard error and the shell exits with a nonzero exit status. Otherwise, the value of parameter is substituted. An interactive shell need not exit. .TP ${parameter:+word} Use Alternative Value. If parameter is unset or null, null is substituted; otherwise, the expansion of word is substituted. .LP d849 2 a850 2 .TP ${#parameter} d853 2 a854 1 .LP d857 1 a857 2 rather than regular expression notation, is used to evaluate the patterns. d862 19 a880 33 .TP ${parameter%word} Remove Smallest Suffix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the smallest portion of the suffix matched by the pattern deleted. .TP ${parameter%%word} Remove Largest Suffix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the largest portion of the suffix matched by the pattern deleted. .TP ${parameter#word} Remove Smallest Prefix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the smallest portion of the prefix matched by the pattern deleted. .TP ${parameter##word} Remove Largest Prefix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the largest portion of the prefix matched by the pattern deleted. .LP .sp 2 .B Command Substitution .sp .LP d884 11 a894 12 .nf $(command) .fi or (``backquoted'' version): .nf `command` .fi .LP d896 1 a896 2 subshell environment and replacing the command substitution with the d899 6 a904 8 the end of the output are not removed; however, during field splitting, they may be translated into s, depending on the value of IFS and quoting that is in effect.) .sp 2 .B Arithmetic Expansion .sp .LP d908 3 a910 5 .nf $((expression)) .fi d915 1 a915 1 .LP d918 1 a918 5 .sp 2 .B White Space Splitting (Field Splitting) .sp .LP d923 20 a942 26 .LP The shell treats each character of the IFS as a delimiter and use the delimiters to split the results of parameter expansion and command substitution into fields. .sp 2 .B Pathname Expansion (File Name Generation) .sp .LP Unless the -f flag is set, file name generation is performed after word splitting is complete. Each word is viewed as a series of patterns, separated by slashes. The process of expansion replaces the word with the names of all existing files whose names can be formed by replacing each pattern with a string that matches the specified pattern. There are two restrictions on this: first, a pattern cannot match a string containing a slash, and second, a pattern cannot match a string starting with a period unless the first character of the pattern is a period. The next section describes the patterns used for both Pathname Expansion and the case(1) command. .sp 2 .B Shell Patterns .sp .LP d945 44 a988 32 ``!'', ``*'', ``?'', and ``[''. These characters lose their special meanings if they are quoted. When command or variable substitution is performed and the dollar sign or back quotes are not double quoted, the value of the variable or the output of the command is scanned for these characters and they are turned into meta-characters. .LP An asterisk (``*'') matches any string of characters. A question mark matches any single character. A left bracket (``['') introduces a character class. The end of the character class is indicated by a ``]''; if the ``]'' is missing then the ``['' matches a ``['' rather than introducing a character class. A character class matches any of the characters between the square brackets. A range of characters may be specified using a minus sign. The character class may be complemented by making an exclamation point the first character of the character class. .LP To include a ``]'' in a character class, make it the first character listed (after the ``!'', if any). To include a minus sign, make it the first or last character listed .sp 2 .B Builtins .sp .LP This section lists the builtin commands which are builtin because they need to perform some operation that can't be performed by a separate process. In addition to these, there are several other commands that may be builtin for efficiency (e.g. printf(1), echo(1), test(1), d990 2 a991 2 .TP : d993 1 a993 2 .TP \&. file d995 1 a995 2 .TP alias [ name[=string] ... ] d997 9 a1005 3 alias ``name'' with value ``string''. If just ``name'' is specified, the value of the alias ``name'' is printed. With no arguments, the alias builtin prints the d1007 1 a1007 2 .TP bg [ job ] ... d1010 1 a1010 2 .TP command command arg... d1012 27 a1038 26 have a shell function with the same name as a builtin command.) .TP cd [ directory ] Switch to the specified directory (default $HOME). If the an entry for CDPATH appears in the environment of the cd command or the shell variable CDPATH is set and the directory name does not begin with a slash, then the directories listed in CDPATH will be searched for the specified directory. The format of CDPATH is the same as that of PATH. In an interactive shell, the cd command will print out the name of the directory that it actually switched to if this is different from the name that the user gave. These may be different either because the CDPATH mechanism was used or because a symbolic link was crossed. .TP eval string... Concatenate all the arguments with spaces. Then re-parse and execute the command. .TP exec [ command arg... ] Unless command is omitted, the shell process is replaced with the specified program (which must be a real program, not a shell builtin or function). Any redirections on the exec command are marked as permanent, d1040 8 a1047 11 .TP exit [ exitstatus ] Terminate the shell process. If exitstatus is given it is used as the exit status of the shell; otherwise the exit status of the preceding command is used. .TP export name... The specified names are exported so that they will appear in the environment of subsequent commands. The only way to un-export a variable is to unset it. The shell allows the value of a variable to be set at the d1049 14 a1062 13 .nf export name=value .fi With no arguments the export command lists the names of all exported variables. .TP fc [-e editor] [first [last]] .TP fc -l [-nr] [first [last]] .TP fc -s [old=new] [first] d1065 2 a1066 3 .RS +.5i .TP 2 -e editor d1069 21 a1089 14 PATH variable. The value in the FCEDIT variable is used as a default when -e is not specified. If FCEDIT is null or unset, the value of the EDITOR variable is used. If EDITOR is null or unset, ed(1) is used as the editor. .TP 2 -l (ell) List the commands rather than invoking an editor on them. The commands are written in the sequence indicated by the first and last operands, as affected by -r, with each command preceded by the command number. .TP 2 -n d1091 8 a1098 6 .TP 2 -r Reverse the order of the commands listed (with -l) or edited (with neither -l nor -s). .TP 2 -s d1100 24 a1123 28 .TP 2 first .TP 2 last Select the commands to list or edit. The number of previous commands that can be accessed are determined by the value of the HISTSIZE variable. The value of first or last or both are one of the following: .TP 2 [+]number A positive number representing a command number; command numbers can be displayed with the -l option. .TP 2 -number A negative decimal number representing the command that was executed number of commands previously. For example, -1 is the immediately previous command. .TP 2 string A string indicating the most recently entered command that begins with that string. If the old=new operand is not also specified with -s, the string form of the first operand cannot contain an embedded equal sign. .TP d1125 2 a1126 2 .TP 2 FCEDIT d1128 1 a1128 2 .TP 2 HISTSIZE d1130 7 a1136 9 .RE .TP fg [ job ] Move the specified job or the current job to the foreground. .TP getopts optstring var The POSIX .I getopts d1138 1 a1138 1 .B Bell Labs d1140 2 a1141 2 .IR getopt(1) . .sp d1145 3 a1147 3 .sp The .I getopts d1149 3 a1151 4 .IR getopt(1) utility due to its handling of arguments containing whitespace. .sp d1153 1 a1153 1 .I getopts d1156 4 a1159 4 .I getopts places the value of the next option from the option string in the list in the shell variable specified by .B var d1161 1 a1161 1 .BR OPTIND . d1163 1 a1163 1 .BR OPTIND d1165 1 a1165 1 .I getopts d1167 1 a1167 1 .BR OPTARG . d1169 1 a1169 1 .BR optstring , d1171 1 a1171 1 .B OPTARG d1173 2 a1174 2 .sp .BR optstring d1176 5 a1180 6 .IR getopt(3) ). If a letter is followed by a colon, the option is expected to have an argument which may or may not be separated from it by white space. If an option character is not found where expected, .I getopts d1182 1 a1182 1 .B var d1184 2 a1185 2 .BR ? ; .I getopts d1187 1 a1187 1 .B OPTARG d1190 1 a1190 1 .B optstring d1192 1 a1192 1 .sp d1195 1 a1195 1 .I getopts d1197 1 a1197 1 .B var d1199 1 a1199 1 .BR -- , d1201 1 a1201 1 .B var d1203 2 a1204 3 .BR ? . .TP hash -rv command... d1211 9 a1219 10 .sp With arguments, the hash command removes the specified commands from the hash table (unless they are functions) and then locates them. With the -v option, hash prints the locations of the commands as it finds them. The -r option causes the hash command to delete all the entries in the hash table except for functions. .TP jobid [ job ] d1222 1 a1222 2 .TP jobs d1225 1 a1225 2 .TP pwd d1233 38 a1270 30 .TP read [ -p prompt ] [ -r ] variable... The prompt is printed if the -p option is specified and the standard input is a terminal. Then a line is read from the standard input. The trailing newline is deleted from the line and the line is split as described in the section on word splitting above, and the pieces are assigned to the variables in order. If there are more pieces than variables, the remaining pieces (along with the characters in IFS that separated them) are assigned to the last variable. If there are more variables than pieces, the remaining variables are assigned the null string. .sp By default, unless the -r option is specified, the backslash (\\) acts as an escape character, causing the following character to be treated literally. If a backslash is followed by a newline, the backslash and the newline will be deleted. .TP readonly name... The specified names are marked as read only, so that they cannot be subsequently modified or unset. The shell allows the value of a variable to be set at the same time it is marked read only by writing .TP readonly name=value With no arguments the readonly command lists the names of all read only variables. .TP set [ { -options | +options | -- } ] arg... d1272 1 a1272 1 .sp d1275 1 a1275 1 .sp d1278 14 a1291 15 called ``Argument List Processing''. .sp The third use of the set command is to set the values of the shell's positional parameters to the specified args. To change the positional parameters without changing any options, use ``--'' as the first argument to set. If no args are present, the set command will clear all the positional parameters (equivalent to executing ``shift $#''.) .TP setvar variable value Assigns value to variable. (In general it is better to write variable=value rather than using setvar. Setvar is intended to be used in functions that assign values to variables whose names are passed as d1293 44 a1336 43 .TP shift [ n ] Shift the positional parameters n times. A shift sets the value of $1 to the value of $2, the value of $2 to the value of $3, and so on, decreasing the value of $# by one. If there are zero positional parameters, shifting doesn't do anything. .TP trap [ action ] signal... Cause the shell to parse and execute action when any of the specified signals are received. The signals are specified by signal number. Action may be null or omitted; the former causes the specified signal to be ignored and the latter causes the default action to be taken. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The trap command has no effect on signals that were ignored on entry to the shell. .TP type [name]... Interpret each name as a command and print the resolution of the command search. Possible resolutions are: shell keyword, alias, shell builtin, command, tracked alias and not found. For aliases the alias expansion is printed; for commands and tracked aliases the complete pathname of the command is printed. .TP ulimit [ -H | -S ] [ -a | -tfdscmlpn [ value ] ] Inquire about or set the hard or soft limits on processes or set new limits. The choice between hard limit (which no process is allowed to violate, and which may not be raised once it has been lowered) and soft limit (which causes processes to be signaled but not necessarily killed, and which may be raised) is made with these flags: .RS +.5i .TP 2 -H set or inquire about hard limits .TP 2 -S set or inquire about soft limits If neither -H nor -S is specified, the soft limit is displayed or both limits are set. If both are specified, the last one wins. .LP 2 d1339 1 a1339 2 .TP 2 -a d1341 1 a1341 2 .TP 2 -t d1343 1 a1343 2 .TP 2 -f d1346 1 a1346 2 .TP 2 -d d1348 1 a1348 2 .TP 2 -s d1350 2 a1351 3 .TP 2 -c show or set the limit on the largest core dump size that can be produced d1353 1 a1353 2 .TP 2 -m d1356 1 a1356 2 .TP 2 -l d1360 1 a1360 2 .TP 2 -p d1363 1 a1363 2 .TP 2 -n d1365 118 a1482 44 .LP 2 If none of these is specified, it is the limit on file size that is shown or set. If value is specified, the limit is set to that number; otherwise the current limit is displayed. .RE .TP umask [ mask ] Set the value of umask (see umask(2)) to the specified octal value. If the argument is omitted, the umask value is printed. .TP unalias [-a] [name] If ``name'' is specified, the shell removes that alias. If ``-a'' is specified, all aliases are removed. .TP unset name... The specified variables and functions are unset and unexported. If a given name corresponds to both a variable and a function, both the variable and the function are unset. .TP wait [ job ] Wait for the specified job to complete and return the exit status of the last process in the job. If the argument is omitted, wait for all jobs to complete and the return an exit status of zero. .LP .sp 2 .B Command Line Editing .sp .LP When sh is being used interactively from a terminal, the current command and the command history (see fc in Builtins) can be edited using vi-mode command-line editing. This mode uses commands, described below, similar to a subset of those described in the vi man page. The command set -o vi enables vi-mode editing and place sh into vi insert mode. With vi-mode enabled, sh can be switched between insert mode and command mode. The editor is not described in full here, but will be in a later document. It's similar to vi: typing will throw you into command VI command mode. Hitting while in command mode will pass the line to the shell. .SH HISTORY d1484 1 a1484 1 .I sh d1486 1 a1486 1 Version 1 AT&T UNIX. d1488 10 @ 1.24 log @Modify to better document getopts. This fixes PR# 704. Much thanks to Christos for helping me out with this. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.23 1998/07/04 06:52:07 ross Exp $ d1277 1 a1277 1 and and write output to standard error. By specifying a colon as the d1283 3 a1285 1 If there are no remaining arguments, getopt will set @ 1.23 log @Small edit to n1>&n2 description. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.22 1997/11/05 14:05:31 kleink Exp $ d1214 1 a1214 1 The number of previous commands that are accessable. d1222 69 a1290 9 The POSIX getopts command. The getopts command deprecates the older getopt command. The first argument should be a series of letters, each possibly followed by a colon which indicates that the option takes an argument. The specified variable is set to the parsed option. The index of the next argument is placed into the shell variable OPTIND. If an option takes an argument, it is placed into the shell variable OPTARG. If an invalid option is encountered, var is set to '?'. It returns a false value (1) when it encounters the end of the options. d1409 1 a1409 1 and soft limit (which causes processes to be signalled but not @ 1.22 log @Per 1003.2, the (builtin) read utility shall treat the backslash as an escape character (including line continuation), unless the `-r' option is specified: * adopt to this behaviour, add the `-r' option to disable it; * remove the `-e' option, which was previously necessary to get this behaviour. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.21 1997/07/10 23:07:04 phil Exp $ d370 1 a370 2 Duplicate standard output (or n) from n2. @ 1.21 log @Add a missing ) in the description of the builtin "set". @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.20 1997/05/23 19:40:30 cjs Exp $ d1266 1 a1266 1 read [ -p prompt ] [ -e ] variable... d1279 4 a1282 7 The -e option causes any backslashes in the input to be treated specially. If a backslash is followed by a newline, the backslash and the newline will be deleted. If a backslash is followed by any other character, the backslash will be deleted and the following character will be treated as though it were not in IFS, even if it is. @ 1.21.2.1 log @Pull rev 1.22 up from trunk (kleink) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.22 1997/11/05 14:05:31 kleink Exp $ d1266 1 a1266 1 read [ -p prompt ] [ -r ] variable... d1279 7 a1285 4 By default, unless the -r option is specified, the backslash (\\) acts as an escape character, causing the following character to be treated literally. If a backslash is followed by a newline, the backslash and the newline will be deleted. @ 1.20 log @Add documentation for ulimit command, courtsey of Eric Fischer . @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.19 1997/03/08 13:28:45 mouse Exp $ d1313 1 a1313 1 to executing ``shift $#''. @ 1.19 log @alternate -> alternative, per PR 2643 @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.18 1997/02/06 23:24:54 christos Exp $ d1347 61 @ 1.18 log @add type builtin. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.17 1996/10/16 15:20:01 christos Exp $ d913 1 a913 1 Use Alternate Value. If parameter is unset @ 1.17 log @PR/2808: Add HISTORY section and documentation of getopts. (from FreeBSD) @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.16 1996/09/02 21:28:21 christos Exp $ d1339 8 @ 1.16 log @Apply PR#2721 from VaX#n8: make man page more lucid in places. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.15 1995/05/11 21:30:18 christos Exp $ d350 1 a350 1 [n]> file d353 1 a353 1 [n]>| file d356 1 a356 1 [n]>> file d359 1 a359 1 [n]< file d362 1 a362 1 [n1]<&n2 d366 1 a366 1 [n]<&- d369 1 a369 1 [n1]>&n2 d373 1 a373 1 [n]>&- d376 1 a376 1 [n]<> file d837 1 a837 1 .sp a940 1 d1048 1 a1048 1 there special meanings if they are quoted. When command d1224 8 d1241 2 a1242 2 With arguments, the hash command removes the specified commands from the hash table (unless they are d1341 2 a1342 2 Set the value of umask (see umask(2)) to the specified octal value. If the argument is omitted, the d1376 6 @ 1.15 log @Merge in my changes from vangogh, and fix the x=`false`; echo $? == 0 bug. @ text @d1 1 a1 1 .\" $NetBSD$ d194 1 a194 1 Enable the builtin vi(1) command line editor (disables d198 1 a198 1 Enable the builtin emacs(1) command line editor (disables d244 2 a245 1 meaning of all the characters. d401 2 a402 1 There are three types of commands: shell functions, builtin commands, and normal programs -- and the d406 2 a407 1 When a shell function is executed, all of the shell positional parameters (except $0, which remains unchanged) are d415 1 d417 2 a418 1 Shell builtins are executed internally to the shell, without spawning a new process. d425 5 a429 2 program. If the program is a shell procedure, the shell will interpret the program in a subshell. The shell will d431 2 a432 2 be as if a new shell had been invoked to handle the shell procedure, except that the location of commands located in d434 5 d445 7 a451 4 builtin command by that name. Finally, it searches each entry in PATH in turn for the command. .LP d456 2 a457 3 may be indicated by an empty directory name. .LP Command names containing a slash are simply executed without performing any of the above searches. d468 1 a468 1 an executed function. d493 1 a493 1 .B Pipeline d499 2 a500 1 of the next command. d540 6 d576 3 d586 3 d609 3 a611 1 The two lists are executed repeatedly while the exit status of the first list is zero. The until command is similar, but has the word until in place of while d634 2 a635 1 Continue continues with the next iteration of the innermost loop. These are implemented as builtin commands. d649 3 a651 1 d666 11 d708 2 a709 1 local to function f, which then calls function g, references to the variable x made inside g will refer to the d927 2 a928 1 processing. In each case, pattern matching notation (see Shell Patterns), rather d1029 2 a1030 1 Unless the -f flag is set, file name generation is performed after word splitting is complete. Each word is d1035 2 a1036 1 There are two restrictions on this: first, a pattern cannot match a string containing a slash, and second, d1046 2 a1047 1 A pattern consists of normal characters, which match themselves, and meta-characters. The meta-characters are d1077 2 a1078 1 that can't be performed by a separate process. In addition to these, there are several other commands that may d1100 2 a1101 1 Execute the specified builtin command. (This is useful when you have a shell function with the same name d1111 2 a1112 1 CDPATH is the same as that of PATH. In an interactive shell, the cd command will print out the name of d1126 2 a1127 1 redirections on the exec command are marked as permanent, so that they are not undone when the exec command finishes. d1234 2 a1235 1 With arguments, the hash command removes the specified commands from the hash table (unless they are d1266 2 a1267 1 If there are more pieces than variables, the remaining pieces (along with the characters in IFS that d1269 2 a1270 1 If there are more variables than pieces, the remaining variables are assigned the null string. d1276 2 a1277 1 character, the backslash will be deleted and the following character will be treated as though it were d1303 2 a1304 1 changing any options, use ``--'' as the first argument to set. If no args are present, the set command @ 1.15.6.1 log @Update /bin/sh from trunk per request of Christos Zoulas. Fixes many bugs. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.17 1996/10/16 15:20:01 christos Exp $ d194 1 a194 1 Enable the built-in vi(1) command line editor (disables d198 1 a198 1 Enable the built-in emacs(1) command line editor (disables d244 1 a244 2 meaning of all the characters (except single quotes, making it impossible to put single-quotes in a single-quoted string). d349 1 a349 1 [n]> file d352 1 a352 1 [n]>| file d355 1 a355 1 [n]>> file d358 1 a358 1 [n]< file d361 1 a361 1 [n1]<&n2 d365 1 a365 1 [n]<&- d368 1 a368 1 [n1]>&n2 d372 1 a372 1 [n]>&- d375 1 a375 1 [n]<> file d400 1 a400 2 There are three types of commands: shell functions, builtin commands, and normal programs -- and the d404 1 a404 2 When a shell function is executed, all of the shell positional parameters (except $0, which remains unchanged) are a411 1 This all occurs within the current shell. d413 1 a413 2 Shell builtins are executed internally to the shell, without spawning a new process. d420 2 a421 5 program. If the program is not a normal executable file (i.e., if it does not begin with the "magic number" whose ASCII representation is "#!", so execve(2) returns ENOEXEC then) the shell will interpret the program in a subshell. The child shell will d423 2 a424 2 be as if a new shell had been invoked to handle the ad-hoc shell script, except that the location of hashed commands located in a425 5 .LP Note that previous versions of this document and the source code itself misleadingly and sporadically refer to a shell script without a magic number as a "shell procedure". d432 4 a435 7 builtin command by that name. If a builtin command is not found, one of two things happen: .sp 1) Command names containing a slash are simply executed without performing any searches. .sp 2) The shell searches each entry in PATH in turn for the command. d440 3 a442 2 may be indicated implicitly by an empty directory name, or explicitly by a single period. d453 1 a453 1 an executed shell function. d478 1 a478 1 .B Pipelines d484 1 a484 2 of the next command. The standard output of the last command is inherited from the shell, as usual. a523 6 .LP Note that unlike some other shells, each process in the pipeline is a child of the invoking shell (unless it is a shell builtin, in which case it executes in the current shell -- but any effect it has on the environment is wiped). a553 3 .sp 2 .B Short-Circuit List Operators .sp a560 3 .sp 2 .B Flow-Control Constructs -- if, while, for, case .sp d581 1 a581 3 The two lists are executed repeatedly while the exit status of the first list is zero. The until command is similar, but has the word until in place of while, which causes it to d604 1 a604 2 Continue continues with the next iteration of the innermost loop. These are implemented as builtin commands. d618 1 a618 3 .sp 2 .B Grouping Commands Together .sp a632 11 Builtin commands grouped into a (list) will not affect the current shell. The second form does not fork another shell so is slightly more efficient. Grouping commands together this way allows you to redirect their output as though they were one program: .nf { echo -n "hello"; echo " world" } > greeting .fi d664 1 a664 2 local to function f, which then calls function g, references to the variable x made inside g will refer to the d792 1 a792 1 .sp d882 1 a882 2 processing. In each case, pattern matching notation (see Shell Patterns), rather d895 1 d983 1 a983 2 Unless the -f flag is set, file name generation is performed after word splitting is complete. Each word is d988 1 a988 2 There are two restrictions on this: first, a pattern cannot match a string containing a slash, and second, d998 1 a998 2 A pattern consists of normal characters, which match themselves, and meta-characters. The meta-characters are d1000 1 a1000 1 their special meanings if they are quoted. When command d1028 1 a1028 2 that can't be performed by a separate process. In addition to these, there are several other commands that may d1050 1 a1050 2 Execute the specified builtin command. (This is useful when you have a shell function with the same name d1060 1 a1060 2 CDPATH is the same as that of PATH. In an interactive shell, the cd command will print out the name of d1074 1 a1074 2 redirections on the exec command are marked as permanent, so that they are not undone when the exec command finishes. a1171 8 The getopts command deprecates the older getopt command. The first argument should be a series of letters, each possibly followed by a colon which indicates that the option takes an argument. The specified variable is set to the parsed option. The index of the next argument is placed into the shell variable OPTIND. If an option takes an argument, it is placed into the shell variable OPTARG. If an invalid option is encountered, var is set to '?'. It returns a false value (1) when it encounters the end of the options. d1181 1 a1181 2 With arguments, the hash command removes the specified commands from the hash table (unless they are d1212 1 a1212 2 If there are more pieces than variables, the remaining pieces (along with the characters in IFS that d1214 1 a1214 2 If there are more variables than pieces, the remaining variables are assigned the null string. d1220 1 a1220 2 character, the backslash will be deleted and the following character will be treated as though it were d1246 1 a1246 2 changing any options, use ``--'' as the first argument to set. If no args are present, the set command d1276 2 a1277 2 Set the value of umask (see umask(2)) to the specified octal value. If the argument is omitted, the a1310 6 .SH HISTORY A .I sh command appeared in Version 1 AT&T UNIX. It was, however, unmaintainable so we wrote this one. @ 1.15.6.2 log @Pull up latest sh(1). Fixes yet more bugs. @ text @d1 1 a1 1 .\" $NetBSD: sh.1,v 1.15.6.1 1997/01/26 04:57:39 rat Exp $ a1338 8 .TP type [name]... Interpret each name as a command and print the resolution of the command search. Possible resolutions are: shell keyword, alias, shell builtin, command, tracked alias and not found. For aliases the alias expansion is printed; for commands and tracked aliases the complete pathname of the command is printed. @ 1.14 log @convert to new RCS id conventions. @ text @a1 1 .\" d36 1 a36 1 .\" @@(#)sh.1 8.4 (Berkeley) 4/18/94 @ 1.13 log @I added the documented in the manual but not implemented variable expansions: ${#WORD} ${WORD%PAT} ${WORD%%PAT} ${WORD#PAT} ${WORD##PAT} @ text @d1 2 d37 1 a37 2 .\" from: @@(#)sh.1 8.4 (Berkeley) 4/18/94 .\" $Id: sh.1,v 1.12 1995/01/12 23:35:56 jtc Exp $ @ 1.12 log @Describe the : shell builtin. Fixes PR #712. @ text @d36 1 a36 1 .\" $Id: sh.1,v 1.11 1994/06/11 16:12:33 mycroft Exp $ a887 1 (UNIMPLEMENTED IN 4.4alpha) @ 1.11 log @Add RCS ids. @ text @d36 1 a36 1 .\" $Id: $ d1033 6 a1065 3 .TP \&. file The commands in the specified file are read and executed by the shell. @ 1.10 log @sync with 4.4lite @ text @d35 2 a36 1 .\" @@(#)sh.1 8.4 (Berkeley) 4/18/94 @ 1.9 log @Comment out sections of the manpages that are not, and will probably never be, appropriate for ash as configured for NetBSD. In particular the /u "magic" directory, and atty(1) support. @ text @d1 2 a2 2 .\" Copyright (c) 1991 The Regents of the University of California. .\" All rights reserved. d35 1 a35 2 .\" from: @@(#)sh.1 5.1 (Berkeley) 3/7/91 .\" $Id: sh.1,v 1.8 1994/02/03 17:47:48 jtc Exp $ d37 2 a38 28 .TH SH 1 "March 7, 1991" .UC 7 .de h \" subheading .sp .ti -0.3i .B "\\$1" .PP .. .de d \" begin display .sp .in +4 .nf .. .de e \" end display .in -4 .fi .sp .. .de c \" command, etc. .br .HP 5 \fB\\$1\fR .br .. .de b \" begin builtin command .HP 5 .B \\$1 .. d40 1 a40 1 ash \- a shell d42 1 a42 13 .B ash [ .B -efIijnsxz ] [ .B +efIijnsxz ] [ .B -c .I command ] [ .I arg ] ... .SH COPYRIGHT Copyright 1989 by Kenneth Almquist. d44 463 a506 138 .I Ash is a version of .I sh with features similar to those of the System V shell. This manual page lists all the features of .I ash but concentrates on the ones not in other shells. .h "Invocation" If the .B -c options is given, then the shell executes the specified shell command. The .B -s flag cause the shell to read commands from the standard input (after executing any command specified with the .B -c option. If neither the .B -s or .B -c options are set, then the first .I arg is taken as the name of a file to read commands from. If this is impossible because there are no arguments following the options, then .I ash will set the .B -s flag and will read commands from the standard input. .PP The shell sets the initial value of the positional parameters from the .IR arg s remaining after any .I arg used as the name of a file of commands is deleted. .PP The flags (other than .BR -c ) are set by preceding them with ``-'' and cleared by preceding them with ``+''; see the .I set builtin command for a list of flags. If no value is specified for the .B -i flag, the .B -s flag is set, and the standard input and output of the shell are connected to terminals, then the .B -i flag will be set. If no value is specified for the .B -j flag, then the .B -j flag will be set if the .B -i flag is set. .PP When the shell is invoked with the .B -c option, it is good practice to include the .I -i flag if the command was entered interactively by a user. For compatibility with the System V shell, the .I -i option should come after the .B -c option. .PP If the first character of argument zero to the shell is ``-'', the shell is assumed to be a login shell, and the files .B /etc/profile and .B .profile are read if they exist. If the environment variable SHINIT is set on entry to the shell, the commands in SHINIT are normally parsed and executed. SHINIT is not examined if the shell is a login shell, or if it the shell is running a shell procedure. (A shell is considered to be running a shell procedure if neither the .B -s nor the .B -c options are set.) .h "Control Structures" A .I list is a sequence of zero or more commands separated by newlines, semicolons, or ampersands, and optionally terminated by one of these three characters. (This differs from the System V shell, which requires a list to contain at least one command in most cases.) The commands in a list are executed in the order they are written. If command is followed by an ampersand, the shell starts the command and immediately proceed onto the next command; otherwise it waits for the command to terminate before proceeding to the next one. .PP ``&&'' and ``||'' are binary operators. ``&&'' executes the first command, and then executes the second command iff the exit status of the first command is zero. ``||'' is similar, but executes the second command iff the exit status of the first command is nonzero. ``&&'' and ``||'' both have the same priority. .PP The ``|'' operator is a binary operator which feeds the standard output of the first command into the standard input of the second command. The exit status of the ``|'' operator is the exit status of the second command. ``|'' has a higher priority than ``||'' or ``&&''. .PP An .I if command looks like .d \fBif\fR list \fBthen\fR list .ti -\w'[ 'u [ \fBelif\fR list \fBthen\fR list ] ... .ti -\w'[ 'u [ \fBelse\fR list ] \fBfi\fR .e .PP A .I while command looks like .d \fBwhile\fR list \fBdo\fR list \fBdone\fR .e The two lists are executed repeatedly while the exit status of the first list is zero. The .I until command is similar, but has the word .B until in place of .B while repeats until the exit status of the first list d508 111 a618 53 .PP The .I for command looks like .d \fBfor\fR variable \fBin\fR word... \fBdo\fR list \fBdone\fR .e The words are expanded, and then the list is executed repeatedly with the variable set to each word in turn. .B do and .B done may be replaced with ``{'' and ``}''. .PP The .I break and .I continue commands look like .d \fBbreak\fR [ num ] \fBcontinue\fR [ num ] .e .I Break terminates the .I num innermost .I for or .I while loops. .I Continue continues with the next iteration of the .IR num'th innermost loop. These are implemented as builtin commands. .PP The .I case command looks like .d \fBcase\fR word \fBin\fR pattern\fB)\fR list \fB;;\fR \&... \fBesac\fR .e The pattern can actually be one or more patterns (see .I Patterns below), separated by ``|'' characters. .PP d620 5 a624 3 .d \fB(\fRlist\fB)\fR .e d626 5 a630 3 .d \fB{\fR list; \fB}\fR .e d632 429 a1060 393 .PP A function definition looks like .d name \fB( )\fR command .e A function definition is an executable statement; when executed it installs a function named .B name and returns an exit status of zero. The command is normally a list enclosed between ``{'' and ``}''. .PP Variables may be declared to be local to a function by using a .I local command. This should appear as the first statement of a function, and looks like .d \fBlocal\fR [ variable | \fB-\fR ] ... .e .I Local is implemented as a builtin command. .PP When a variable is made local, it inherits the initial value and exported and readonly flags from the variable with the same name in the surrounding scope, if there is one. Otherwise, the variable is initially unset. .I Ash uses dynamic scoping, so that if you make the variable .B x local to function .IR f , which then calls function .IR g , references to the variable .B x made inside .I g will refer to the variable .B x declared inside .IR f , not to the global variable named .BR x . .PP The only special parameter than can be made local is ``\fB-\fR''. Making ``\fB-\fR'' local any shell options that are changed via the .I set command inside the function to be restored to their original values when the function returns. .PP The .I return command looks like .d \fBreturn\fR [ exitstatus ] .e It terminates the currently executing function. .I Return is implemented as a builtin command. .h "Simple Commands" A simple command is a sequence of words. The execution of a simple command proceeds as follows. First, the leading words of the form ``name=value'' are stripped off and assigned to the environment of the command. Second, the words are expanded. Third, the first remaining word is taken as the command name that command is located. Fourth, any redirections are performed. Fifth, the command is executed. We look at these operations in reverse order. .PP The execution of the command varies with the type of command. There are three types of commands: shell functions, builtin commands, and normal programs. .PP When a shell function is executed, all of the shell positional parameters (except $0, which remains unchanged) are set to the parameters to the shell function. The variables which are explicitly placed in the environment of the command (by placing assignments to them before the function name) are made local to the function and are set to values given. Then the command given in the function definition is executed. The positional parameters are restored to their original values when the command completes. .PP Shell builtins are executed internally to the shell, without spawning a new process. .PP When a normal program is executed, the shell runs the program, passing the parameters and the environment to the program. If the program is a shell procedure, the shell will interpret the program in a subshell. The shell will reinitialize itself in this case, so that the effect will be as if a new shell had been invoked to handle the shell procedure, except that the location of commands located in the parent shell will be remembered by the child. If the program is a file beginning with ``#!'', the remainder of the first line specifies an interpreter for the program. The shell (or the operating system, under Berkeley UNIX) will run the interpreter in this case. The arguments to the interpreter will consist of any arguments given on the first line of the program, followed by the name of the program, followed by the arguments passed to the program. .h "Redirection" Input/output redirections can be intermixed with the words in a simple command and can be placed following any of the other commands. When redirection occurs, the shell saves the old values of the file descriptors and restores them when the command completes. The ``<'', ``>'', and ``>>'' redirections open a file for input, output, and appending, respectively. The ``<&digit'' and ``>&digit'' makes the input or output a duplicate of the file descriptor numbered by the digit. If a minus sign is used in place of a digit, the standard input or standard output are closed. .PP The ``<<\ word'' redirection takes input from a .I here document. As the shell encounters ``<<'' redirections, it collects them. The next time it encounters an unescaped newline, it reads the documents in turn. The word following the ``<<'' specifies the contents of the line that terminates the document. If none of the quoting methods ('', "", or \e) are used to enter the word, then the document is treated like a word inside double quotes: ``$'' and backquote are expanded and backslash can be used to escape these and to continue long lines. The word cannot contain any variable or command substitutions, and its length (after quoting) must be in the range of 1 to 79 characters. If ``<<-'' is used in place of ``<<'', then leading tabs are deleted from the lines of the document. (This is to allow you do indent shell procedures containing here documents in a natural fashion.) .PP Any of the preceding redirection operators may be preceded by a single digit specifying the file descriptor to be redirected. There cannot be any white space between the digit and the redirection operator. .h "Path Search" When locating a command, the shell first looks to see if it has a shell function by that name. Then, if PATH does not contain an entry for "%builtin", it looks for a builtin command by that name. Finally, it searches each entry in PATH in turn for the command. .PP The value of the PATH variable should be a series of entries separated by colons. Each entry consists of a directory name, or a directory name followed by a flag beginning with a percent sign. The current directory should be indicated by an empty directory name. .PP If no percent sign is present, then the entry causes the shell to search for the command in the specified directory. If the flag is ``%builtin'' then the list of shell builtin commands is searched. If the flag is ``%func'' then the directory is searched for a file which is read as input to the shell. This file should define a function whose name is the name of the command being searched for. .PP Command names containing a slash are simply executed without performing any of the above searches. .h "The Environment" The environment of a command is a set of name/value pairs. When the shell is invoked, it reads these names and values, sets the shell variables with these names to the corresponding values, and marks the variables as exported. The .I export command can be used to mark additional variables as exported. .PP The environment of a command is constructed by constructing name/value pairs from all the exported shell variables, and then modifying this set by the assignments which precede the command, if any. .h "Expansion" The process of evaluating words when a shell procedure is executed is called .IR expansion . Expansion consists of four steps: variable substitution, command substitution, word splitting, and file name generation. If a word is the expression following the word .B case in a case statement, the file name which follows a redirection symbol, or an assignment to the environment of a command, then the word cannot be split into multiple words. In these cases, the last two steps of the expansion process are omitted. .h "Variable Substitution" To be written. .h "Command Substitution" .I Ash accepts two syntaxes for command substitution: .b `\fIlist\fR` .e and .b $(\fIlist\fR) .e Either of these may be included in a word. During the command substitution process, the command (syntactly a .IR list ) will be executed and anything that the command writes to the standard output will be captured by the shell. The final newline (if any) of the output will be deleted; the rest of the output will be substituted for the command in the word. .h "Word Splitting" When the value of a variable or the output of a command is substituted, the resulting text is subject to word splitting, unless the dollar sign introducing the variable or backquotes containing the text were enclosed in double quotes. In addition, ``$@@'' is subject to a special type of splitting, even in the presence of double quotes. .PP Ash uses two different splitting algorithms. The normal approach, which is intended for splitting text separated by which space, is used if the first character of the shell variable IFS is a space. Otherwise an alternative experimental algorithm, which is useful for splitting (possibly empty) fields separated by a separator character, is used. .PP When performing splitting, the shell scans the replacement text looking for a character (when IFS does not begin with a space) or a sequence of characters (when IFS does begin with a space), deletes the character or sequence of characters, and spits the word into two strings at that point. When IFS begins with a space, the shell deletes either of the strings if they are null. As a special case, if the word containing the replacement text is the null string, the word is deleted. .PP The variable ``$@@'' is special in two ways. First, splitting takes place between the positional parameters, even if the text is enclosed in double quotes. Second, if the word containing the replacement text is the null string and there are no positional parameters, then the word is deleted. The result of these rules is that "$@@" is equivalent to "$1" "$2" ... "$\fIn\fR", where \fIn\fR is the number of positional parameters. (Note that this differs from the System V shell. The System V documentation claims that "$@@" behaves this way; in fact on the System V shell "$@@" is equivalent to "" when there are no positional parameters.) .h "File Name Generation" Unless the .B -f flag is set, file name generation is performed after word splitting is complete. Each word is viewed as a series of patterns, separated by slashes. The process of expansion replaces the word with the names of all existing files whose names can be formed by replacing each pattern with a string that matches the specified pattern. There are two restrictions on this: first, a pattern cannot match a string containing a slash, and second, a pattern cannot match a string starting with a period unless the first character of the pattern is a period. .PP If a word fails to match any files and the .B -z flag is not set, then the word will be left unchanged (except that the meta-characters will be converted to normal characters). If the .B -z flag is set, then the word is only left unchanged if none of the patterns contain a character that can match anything besides itself. Otherwise the .B -z flag forces the word to be replaced with the names of the files that it matches, even if there are zero names. .h "Patterns" A .I pattern consists of normal characters, which match themselves, and meta-characters. The meta-characters are ``!'', ``*'', ``?'', and ``[''. These characters lose there special meanings if they are quoted. When command or variable substitution is performed and the dollar sign or back quotes are not double quoted, the value of the variable or the output of the command is scanned for these characters and they are turned into meta-characters. .PP Two exclamation points at the beginning of a pattern function as a ``not'' operator, causing the pattern to match any string that the remainder of the pattern does .I not match. Other occurrences of exclamation points in a pattern match exclamation points. Two exclamation points are required rather than one to decrease the incompatibility with the System V shell (which does not treat exclamation points specially). .PP An asterisk (``*'') matches any string of characters. A question mark matches any single character. A left bracket (``['') introduces a character class. The end of the character class is indicated by a ``]''; if the ``]'' is missing then the ``['' matches a ``['' rather than introducing a character class. A character class matches any of the characters between the square brackets. A range of characters may be specified using a minus sign. The character class may be complemented by making an exclamation point the first character of the character class. .PP To include a ``]'' in a character class, make it the first character listed (after the ``!'', if any). To include a minus sign, make it the first or last character listed. .\" .h "The /u Directory" .\" By convention, the name ``/u/user'' refers to the home directory of the .\" specified user. There are good reasons why this feature should be supported .\" by the file system (using a feature such as symbolic links) rather than .\" by the shell, but .\" .I ash .\" is capable of performing this mapping if the file system doesn't. .\" If the mapping is done by .\" .IR ash , .\" setting the .\" .B -f .\" flag will turn it off. .h "Character Set" .I Ash silently discards nul characters. Any other character will be handled correctly by .IR ash , including characters with the high order bit set. .h "Job Names and Job Control" The term .I job refers to a process created by a shell command, or in the case of a pipeline, to the set of processes in the pipeline. The ways to refer to a job are: .b %\fInumber\fR %\fIstring\fR %% \fIprocess_id\fR .e The first form identifies a job by job number. When a command is run, .I ash assigns it a job number (the lowest unused number is assigned). The second form identifies a job by giving a prefix of the command used to create the job. The prefix must be unique. If there is only one job, then the null prefix will identify the job, so you can refer to the job by writing ``%''. The third form refers to the \fIcurrent job\fR. The current job is the last job to be stopped while it was in the foreground. (See the next paragraph.) The last form identifies a job by giving the process id of the last process in the job. .PP If the operating system that .I ash is running on supports job control, .I ash will allow you to use it. In this case, typing the suspend character (typically ^Z) while running a command will return you to .I ash and will make the suspended command the current job. You can then continue the job in the background by typing .IR bg , or you can continue it in the foreground by typing .IR fg . .\" .h "Atty" .\" If the shell variable ATTY is set, and the shell variable TERM is not .\" set to ``emacs'', then \fIash\fR generates appropriate escape sequences .\" to talk to .\" .IR atty (1). .h "Exit Statuses" By tradition, an exit status of zero means that a command has succeeded and a nonzero exit status indicates that the command failed. This is better than no convention at all, but in practice it is extremely useful to allow commands that succeed to use the exit status to return information to the caller. A variety of better conventions have been proposed, but none of them has met with universal approval. The convention used by \fIash\fR and all the programs included in the \fIash\fR distribution is as follows: .ta 1i 2i .nf 0 Success. 1 Alternate success. 2 Failure. 129-... Command terminated by a signal. .fi The \fIalternate success\fR return is used by commands to indicate various conditions which are not errors but which can, with a little imagination, be conceived of as less successful than plain success. For example, .I test returns 1 when the tested condition is false and .I getopts returns 1 when there are no more options. Because this convention is not used universally, the .B -e option of .I ash causes the shell to exit when a command returns 1 even though that contradicts the convention described here. .PP When a command is terminated by a signal, the uses 128 plus the signal number as the exit code for the command. .h "Builtin Commands" This concluding section lists the builtin commands which are builtin because they need to perform some operation that can't be performed by a separate process. .\" In addition to these, there are several other commands .\" .RI ( catf , .\" .IR echo , .\" .IR expr , .\" .IR line , .\" .IR nlecho , .\" .IR test , .\" .RI `` : '', .\" and .\" .IR true ) .\" which can optionally be compiled into the shell. The builtin commands described below that accept options use the System V Release 2 .IR getopt (3) syntax. .sp .b ":" .br No effect; the command does nothing and returns a zero exit code. .b ".\fI\h'0.1i'file" .br d1062 246 a1307 453 .b bg [ .I job ] ... .br Continue the specified jobs (or the current job if no jobs are given) in the background. This command is only available on systems with Berkeley job control. .b bltin .IR "command arg" ... .br Execute the specified builtin command. (This is useful when you have a shell function with the same name as a builtin command.) .b cd [ .I directory ] .br Switch to the specified directory (default $HOME). If the an entry for CDPATH appears in the environment of the cd command or the shell variable CDPATH is set and the directory name does not begin with a slash, then the directories listed in CDPATH will be searched for the specified directory. The format of CDPATH is the same as that of PATH. In an interactive shell, the cd command will print out the name of the directory that it actually switched to if this is different from the name that the user gave. These may be different either because the CDPATH mechanism was used or because a symbolic link was crossed. .b eval .IR string ... .br The strings are parsed as shell commands and executed. (This differs from the System V shell, which concatenates the arguments (separated by spaces) and parses the result as a single command.) .b exec [ .IR "command arg" ... ] .br Unless .I command is omitted, the shell process is replaced with the specified program (which must be a real program, not a shell builtin or function). Any redirections on the exec command are marked as permanent, so that they are not undone when the exec command finishes. If the command is not found, the exec command causes the shell to exit. .b exit [ .I exitstatus ] .br Terminate the shell process. If .I exitstatus is given it is used as the exit status of the shell; otherwise the exit status of the preceding command is used. .b export .IR name ... .br The specified names are exported so that they will appear in the environment of subsequent commands. The only way to un-export a variable is to unset it. .I Ash allows the value of a variable to be set at the same time it is exported by writing .d \fBexport\fR name=value .e With no arguments the export command lists the names of all exported variables. .b fg [ .I job ] .br Move the specified job or the current job to the foreground. This command is only available on systems with Berkeley job control. .b getopts .I optstring .I var .br The System V .I getopts command. .b hash .B -rv .IR command ... .br The shell maintains a hash table which remembers the locations of commands. With no arguments whatsoever, the hash command prints out the contents of this table. Entries which have not been looked at since the last .I cd command are marked with an asterisk; it is possible for these entries to be invalid. .sp With arguments, the hash command removes the specified commands from the hash table (unless they are functions) and then locates them. With the .B -v option, .I hash prints the locations of the commands as it finds them. The .B -r option causes the .I hash command to delete all the entries in the hash table except for functions. .b jobid [ .I job ] .br Print the process id's of the processes in the job. If the job argument is omitted, use the current job. .b jobs .br This command lists out all the background processes which are children of the current shell process. .b lc [ .I function-name ] .br The function name is defined to execute the last command entered. If the function name is omitted, the last command executed is executed again. This command only works if the .B -i flag is set. .b pwd .br Print the current directory. The builtin command may differ from the program of the same name because the builtin command remembers what the current directory is rather than recomputing it each time. This makes it faster. However, if the current directory is renamed, the builtin version of pwd will continue to print the old name for the directory. .b read [ .B -p .I prompt ] [ .B -e ] .IR variable ... .br The prompt is printed if the .B -p option is specified and the standard input is a terminal. Then a line is read from the standard input. The trailing newline is deleted from the line and the line is split as described in the section on word splitting above, and the pieces are assigned to the variables in order. If there are more pieces than variables, the remaining pieces (along with the characters in IFS that separated them) are assigned to the last variable. If there are more variables than pieces, the remaining variables are assigned the null string. .sp The .B -e option causes any backslashes in the input to be treated specially. If a backslash is followed by a newline, the backslash and the newline will be deleted. If a backslash is followed by any other character, the backslash will be deleted and the following character will be treated as though it were not in IFS, even if it is. .b readonly .IR name ... .br The specified names are marked as read only, so that they cannot be subsequently modified or unset. .I Ash allows the value of a variable to be set at the same time it is marked read only by writing .d \fBreadonly\fR name=value .e With no arguments the readonly command lists the names of all read only variables. .b set [ { .BI - options | .BI + options | .B -- } ] .IR arg ... .br The .I set command performs three different functions. .sp With no arguments, it lists the values of all shell variables. .sp If options are given, it sets the specified option flags, or clears them if the option flags are introduced with a .B + rather than a .BR - . Only the first argument to .I set can contain options. The possible options are: .sp .ta 0.4i .in +0.4i .ti -0.4i \fB-e\fR Causes the shell to exit when a command terminates with a nonzero exit status, except when the exit status of the command is explicitly tested. The exit status of a command is considered to be explicitly tested if the command is used to control an .IR if , .IR elif , .IR while , or .IR until ; or if the command is the left hand operand of an ``&&'' or ``||'' operator. .sp .ti -0.4i \fB-f\fR Turn off file name generation. .sp .ti -0.4i \fB-I\fR Cause the shell to ignore end of file conditions. (This doesn't apply when the shell a script sourced using the ``.'' command.) The shell will in fact exit if it gets 50 eof's in a row. .sp .ti -0.4i \fB-i\fR Make the shell interactive. This causes the shell to prompt for input, to trap interrupts, to ignore quit and terminate signals, and to return to the main command loop rather than exiting on error. .sp .ti -0.4i \fB-j\fR Turns on Berkeley job control, on systems that support it. When the shell starts up, the .B -j is set by default if the .B -i flag is set. .sp .ti -0.4i \fB-n\fR Causes the shell to read commands but not execute them. (This is marginally useful for checking the syntax of scripts.) .sp .ti -0.4i \fB-s\fR If this flag is set when the shell starts up, the shell reads commands from its standard input. The shell doesn't examine the value of this flag any other time. .sp .ti -0.4i \fB-x\fR If this flag is set, the shell will print out each command before executing it. .sp .ti -0.4i \fB-z\fR If this flag is set, the file name generation process may generate zero files. If it is not set, then a pattern which does not match any files will be replaced by a quoted version of the pattern. .in -0.4i .sp The third use of the set command is to set the values of the shell's positional parameters to the specified .IR args . To change the positional parameters without changing any options, use ``\fB--\fR'' as the first argument to .IR set . If no args are present, the set command will leave the value of the positional parameters unchanged, so to set the positional parameters to set of values that may be empty, execute the command .d shift $# .e first to clear out the old values of the positional parameters. .b setvar .I variable .I value .br Assigns .I value to .IR variable . (In general it is better to write .I variable=value rather than using .IR setvar . .I Setvar is intended to be used in functions that assign values to variables whose names are passed as parameters.) .b shift [ .I n ] .br Shift the positional parameters .I n times. A shift sets the value of $1 to the value of $2, the value of $2 to the value of $3, and so on, decreasing the value of $# by one. If there are zero positional parameters, shifting doesn't do anything. .b trap [ .I action ] .IR signal ... .br Cause the shell to parse and execute .I action when any of the specified signals are received. The signals are specified by signal number. .I Action may be null or omitted; the former causes the specified signal to be ignored and the latter causes the default action to be taken. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The trap command has no effect on signals that were ignored on entry to the shell. .b umask [ .I mask ] .br Set the value of umask (see .IR umask (2)) to the specified octal value. If the argument is omitted, the umask value is printed. .b unset .IR name ... .br The specified variables and functions are unset and unexported. If a given name corresponds to both a variable and a function, both the variable and the function are unset. .b wait [ .I job ] .br Wait for the specified job to complete and return the exit status of the last process in the job. If the argument is omitted, wait for all jobs to complete and the return an exit status of zero. .SH EXAMPLES The following function redefines the \fIcd\fR command: .d cd() { if bltin cd "$@@" then if test -f .enter then . .enter else return 0 fi fi } .e This function causes the file ``.enter'' to be read when you enter a directory, if it exists. The \fIbltin\fR command is used to access the real \fIcd\fR command. The ``return 0'' ensures that the function will return an exit status of zero if it successfully changes to a directory that does not contain a ``.enter'' file. Redefining existing commands is not always a good idea, but this example shows that you can do it if you want to. .PP The suspend function distributed with .I ash looks like .d # Copyright (C) 1989 by Kenneth Almquist. All rights reserved. # This file is part of ash, which is distributed under the terms # specified by the Ash General Public License. suspend() { local - set +j kill -TSTP 0 } .e This turns off job control and then sends a stop signal to the current process group, which suspends the shell. (When job control is turned on, the shell ignores the TSTP signal.) Job control will be turned back on when the function returns because ``-'' is local to the function. As an example of what \fInot\fR to do, consider an earlier version of \fIsuspend\fR: .d suspend() { suspend_flag=$- set +j kill -TSTP 0 set -$suspend_flag } .e There are two problems with this. First, \fBsuspend_flag\fR is a global variable rather than a local one, which will cause problems in the (unlikely) circumstance that the user is using that variable for some other purpose. Second, consider what happens if shell received an interrupt signal after it executes the first \fIset\fR command but before it executes the second one. The interrupt signal will abort the shell function, so that the second \fIset\fR command will never be executed and job control will be left off. The first version of \fIsuspend\fR avoids this problem by turning job control off only in a local copy of the shell options. The local copy of the shell options is discarded when the function is terminated, no matter how it is terminated. .SH HINTS Shell variables can be used to provide abbreviations for things which you type frequently. For example, I set .br \h'1i'export h=$HOME .br in my .profile so that I can type the name of my home directory simply by typing ``$h''. .PP When writing shell procedures, try not to make assumptions about what is imported from the environment. Explicitly unset or initialize all variables, rather than assuming they will be unset. If you use cd, it is a good idea to unset CDPATH. .PP People sometimes use ``<&-'' or ``>&-'' to provide no input to a command or to discard the output of a command. A better way to do this is to redirect the input or output of the command to .BR /dev/null . .PP Word splitting and file name generation are performed by default, and you have to explicitly use double quotes to suppress it. This is backwards, but you can learn to live with it. Just get in the habit of writing double quotes around variable and command substitutions, and omit them only when you really want word splitting and file name generation. If you want word splitting but not file name generation, use the .B -f option. .SH AUTHORS Kenneth Almquist .SH "SEE ALSO" echo(1), expr(1), line(1), pwd(1), true(1). .SH BUGS When command substitution occurs inside a here document, the commands inside the here document are run with their standard input closed. For example, the following will not word because the standard input of the .I line command will be closed when the command is run: .d cat <<-! Line 1: $(line) Line 2: $(line) ! .e .PP Unsetting a function which is currently being executed may cause strange behavior. .PP The shell syntax allows a here document to be terminated by an end of file as well as by a line containing the terminator word which follows the ``<<''. What this means is that if you mistype the terminator line, the shell will silently swallow up the rest of your shell script and stick it in the here document. @ 1.8 log @spelling mistakes @ text @d36 1 a36 1 .\" $Id: sh.1,v 1.7 1994/01/27 17:53:28 jtc Exp $ d559 12 a570 12 .h "The /u Directory" By convention, the name ``/u/user'' refers to the home directory of the specified user. There are good reasons why this feature should be supported by the file system (using a feature such as symbolic links) rather than by the shell, but .I ash is capable of performing this mapping if the file system doesn't. If the mapping is done by .IR ash , setting the .B -f flag will turn it off. d615 5 a619 5 .h "Atty" If the shell variable ATTY is set, and the shell variable TERM is not set to ``emacs'', then \fIash\fR generates appropriate escape sequences to talk to .IR atty (1). d655 14 a668 12 separate process. In addition to these, there are several other commands .RI ( catf , .IR echo , .IR expr , .IR line , .IR nlecho , .IR test , .RI `` : '', and .IR true ) which can optionally be compiled into the shell. The builtin commands described below that accept options use the System V Release 2 d672 6 a705 3 .b ".\fI\h'0.1i'file" .br The commands in the specified file are read and executed by the shell. @ 1.7 log @Remove text describing how the dot command does not do a $PATH search, since we added that behavior to get closer to POSIX.2. @ text @d36 1 a36 1 .\" $Id: sh.1,v 1.6 1993/08/01 07:58:14 mycroft Exp $ d297 1 a297 1 command. This should appear as the first staement of a function, d503 1 a503 1 positional paramteters.) d541 1 a541 1 match. Other occurances of exclamation points in a pattern match d677 1 a677 1 This command is only available on systems with Bekeley job control. d748 1 a748 1 This command is only available on systems with Bekeley job control. @ 1.6 log @Add RCS identifiers. @ text @d36 1 a36 1 .\" $Id: $ a700 2 A path search is not done to find the file because the directories in PATH generally contain files that are intended to be executed, not read. @ 1.5 log @Fix typo. @ text @d35 2 a36 3 .\" @@(#)sh.1 5.1 (Berkeley) 3/7/91 .\" .\" $Header: /b/source/CVS/src/bin/sh/sh.1,v 1.4 1993/04/22 03:27:28 mycroft Exp $ @ 1.4 log @Fix various bugs in man pages (from 386BSD patch 130). @ text @d37 1 a37 1 .\" $Header: /b/source/CVS/src/bin/sh/sh.1,v 1.3 1993/03/23 00:29:20 cgd Exp $ d259 1 a259 1 .IRnum'th @ 1.3 log @changed "Id" to "Header" for rcsids @ text @d37 1 a37 1 .\" $Header: sh.1,v 1.2 93/03/22 08:12:50 cgd Exp $ d630 1 a630 1 .ta 1i,2i @ 1.2 log @added rcs ids to all files @ text @d37 1 a37 1 .\" $Id: sh.1,v 1.2 93/03/21 22:16:00 cgd Exp $ @ 1.1 log @Initial revision @ text @d37 2 @ 1.1.1.1 log @initial import of 386bsd-0.1 sources @ text @@ 1.1.1.2 log @44lite code @ text @d1 2 a2 2 .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. d35 1 a35 1 .\" @@(#)sh.1 8.4 (Berkeley) 4/18/94 d37 28 a64 2 .na .TH SH 1 d66 1 a66 1 sh \- command interpreter (shell) d68 13 a80 1 sh [-/+aCefnuvxIimsVEb] [-/+o longname] [arg ...] d82 138 a219 463 .LP Sh is the standard command interpreter for the system. The current version of sh is in the process of being changed to conform with the POSIX 1003.2 and 1003.2a specifications for the shell. This version has many features which make it appear similar in some respects to the Korn shell, but it is not a Korn shell clone (run GNU's bash if you want that). Only features designated by POSIX, plus a few Berkeley extensions, are being incorporated into this shell. We expect POSIX conformance by the time 4.4 BSD is released. This man page is not intended to be a tutorial or a complete specification of the shell. .sp 2 .B Overview .sp .LP The shell is a command that reads lines from either a file or the terminal, interprets them, and generally executes other commands. It is the program that is running when a user logs into the system (although a user can select a different shell with the chsh(1) command). The shell implements a language that has flow control constructs, a macro facility that provides a variety of features in addition to data storage, along with built in history and line editing capabilities. It incorporates many features to aid interactive use and has the advantage that the interpretative language is common to both interactive and non-interactive use (shell scripts). That is, commands can be typed directly to the running shell or can be put into a file and the file can be executed directly by the shell. .sp 2 .B Invocation .sp .LP If no args are present and if the standard input of the shell is connected to a terminal (or if the -i flag is set), the shell is considered an interactive shell. An interactive shell generally prompts before each command and handles programming and command errors differently (as described below). When first starting, the shell inspects argument 0, and if it begins with a dash '-', the shell is also considered a login shell. This is normally done automatically by the system when the user first logs in. A login shell first reads commands from the files /etc/profile and .profile if they exist. If the environment variable ENV is set on entry to a shell, or is set in the .profile of a login shell, the shell next reads commands from the file named in ENV. Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every shell inside the ENV file. To set the ENV variable to some file, place the following line in your .profile of your home directory .nf ENV=$HOME/.shinit; export ENV .fi substituting for ``.shinit'' any filename you wish. Since the ENV file is read for every invocation of the shell, including shell scripts and non-interactive shells, the following paradigm is useful for restricting commands in the ENV file to interactive invocations. Place commands within the ``case'' and ``esac'' below (these commands are described later): .nf case $- in *i*) # commands for interactive use only ... esac .fi If command line arguments besides the options have been specified, then the shell treats the first argument as the name of a file from which to read commands (a shell script), and the remaining arguments are set as the positional parameters of the shell ($1, $2, etc). Otherwise, the shell reads commands from its standard input. .sp 2 .B Argument List Processing .sp .LP All of the single letter options have a corresponding name that can be used as an argument to the '-o' option. The set -o name is provided next to the single letter option in the description below. Specifying a dash ``-'' turns the option on, while using a plus ``+'' disables the option. The following options can be set from the command line or with the set(1) builtin (described later). .TP -a allexport Export all variables assigned to. (UNIMPLEMENTED for 4.4alpha) .TP -C noclobber Don't overwrite existing files with ``>''. (UNIMPLEMENTED for 4.4alpha) .TP -e errexit If not interactive, exit immediately if any untested command fails. The exit status of a command is considered to be explicitly tested if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an ``&&'' or ``||'' operator. .TP -f noglob Disable pathname expansion. .TP -n noexec If not interactive, read commands but do not execute them. This is useful for checking the syntax of shell scripts. .TP -u nounset Write a message to standard error when attempting to expand a variable that is not set, and if the shell is not interactive, exit immediately. (UNIMPLEMENTED for 4.4alpha) .TP -v verbose The shell writes its input to standard error as it is read. Useful for debugging. .TP -x xtrace Write each command to standard error (preceded by a '+ ') before it is executed. Useful for debugging. .TP -I ignoreeof Ignore EOF's from input when interactive. .TP -i interactive Force the shell to behave interactively. .TP -m monitor Turn on job control (set automatically when interactive). .TP -s stdin Read commands from standard input (set automatically if no file arguments are present). This option has no effect when set after the shell has already started running (i.e. with set(1)). .TP -V vi Enable the builtin vi(1) command line editor (disables -E if it has been set). .TP -E emacs Enable the builtin emacs(1) command line editor (disables -V if it has been set). .TP -b notify Enable asynchronous notification of background job completion. (UNIMPLEMENTED for 4.4alpha) .LP .sp 2 .B Lexical Structure .sp .LP The shell reads input in terms of lines from a file and breaks it up into words at whitespace (blanks and tabs), and at certain sequences of characters that are special to the shell called ``operators''. There are two types of operators: control operators and redirection operators (their meaning is discussed later). Following is a list of operators: .nf .sp Control operators: & && ( ) ; ;; | || .sp Redirection operator: < > >| << >> <& >& <<- <> .sp .fi .sp 2 .B Quoting .sp .LP Quoting is used to remove the special meaning of certain characters or words to the shell, such as operators, whitespace, or keywords. There are three types of quoting: matched single quotes, matched double quotes, and backslash. .sp 2 .B Backslash .sp .LP A backslash preserves the literal meaning of the following character, with the exception of . A backslash preceding a is treated as a line continuation. .sp 2 .B Single Quotes .sp .LP Enclosing characters in single quotes preserves the literal meaning of all the characters. .sp 2 .B Double Quotes .sp .LP Enclosing characters within double quotes preserves the literal meaning of all characters except dollarsign ($), backquote (`), and backslash (\\). The backslash inside double quotes is historically weird, and serves to quote only the following characters: $ ` " \\ . Otherwise it remains literal. .sp 2 .B Reserved Words .sp .LP Reserved words are words that have special meaning to the shell and are recognized at the beginning of a line and after a control operator. The following are reserved words: .nf ! elif fi while case else for then { } do done until if esac .fi Their meaning is discussed later. .sp 2 .B Aliases .sp .LP An alias is a name and corresponding value set using the alias(1) builtin command. Whenever a reserved word may occur (see above), and after checking for reserved words, the shell checks the word to see if it matches an alias. If it does, it replaces it in the input stream with its value. For example, if there is an alias called ``lf'' with the value ``ls -F'', then the input .nf lf foobar would become ls -F foobar .fi .LP Aliases provide a convenient way for naive users to create shorthands for commands without having to learn how to create functions with arguments. They can also be used to create lexically obscure code. This use is discouraged. .sp 2 .B Commands .sp .LP The shell interprets the words it reads according to a language, the specification of which is outside the scope of this man page (refer to the BNF in the POSIX 1003.2 document). Essentially though, a line is read and if the first word of the line (or after a control operator) is not a reserved word, then the shell has recognized a simple command. Otherwise, a complex command or some other special construct may have been recognized. .sp 2 .B Simple Commands .sp .LP If a simple command has been recognized, the shell performs the following actions: .sp 1) Leading words of the form ``name=value'' are stripped off and assigned to the environment of the simple command. Redirection operators and their arguments (as described below) are stripped off and saved for processing. .sp 2) The remaining words are expanded as described in the section called ``Expansions'', and the first remaining word is considered the command name and the command is located. The remaining words are considered the arguments of the command. If no command name resulted, then the ``name=value'' variable assignments recognized in 1) affect the current shell. .sp 3) Redirections are performed as described in the next section. .sp 2 .B Redirections .sp .LP Redirections are used to change where a command reads its input or sends its output. In general, redirections open, close, or duplicate an existing reference to a file. The overall format used for redirection is: .nf [n] redir-op file .fi where redir-op is one of the redirection operators mentioned previously. Following is a list of the possible redirections. The [n] is an optional number, as in '3' (not '[3]'), that refers to a file descriptor. .TP [n]> file Redirect standard output (or n) to file. .TP [n]>| file Same, but override the -C option. .TP [n]>> file Append standard output (or n) to file. .TP [n]< file Redirect standard input (or n) from file. .TP [n1]<&n2 Duplicate standard input (or n1) from file descriptor n2. .TP [n]<&- Close standard input (or n). .TP [n1]>&n2 Duplicate standard output (or n) from n2. .TP [n]>&- Close standard output (or n). .TP [n]<> file Open file for reading and writing on standard input (or n). .LP The following redirection is often called a ``here-document''. .nf [n]<< delimiter here-doc-text... delimiter .fi All the text on successive lines up to the delimiter is saved away and made available to the command on standard input, or file descriptor n if it is specified. If the delimiter as specified on the initial line is quoted, then the here-doc-text is treated literally, otherwise the text is subjected to parameter expansion, command substitution, and arithmetic expansion (as described in the section on ``Expansions''). If the operator is ``<<-'' instead of ``<<'', then leading tabs in the here-doc-text are stripped. .sp 2 .B Search and Execution .sp .LP There are three types of commands: shell functions, builtin commands, and normal programs -- and the command is searched for (by name) in that order. They each are executed in a different way. .LP When a shell function is executed, all of the shell positional parameters (except $0, which remains unchanged) are set to the arguments of the shell function. The variables which are explicitly placed in the environment of the command (by placing assignments to them before the function name) are made local to the function and are set to the values given. Then the command given in the function definition is executed. The positional parameters are restored to their original values when the command completes. .LP Shell builtins are executed internally to the shell, without spawning a new process. .LP Otherwise, if the command name doesn't match a function or builtin, the command is searched for as a normal program in the filesystem (as described in the next section). When a normal program is executed, the shell runs the program, passing the arguments and the environment to the program. If the program is a shell procedure, the shell will interpret the program in a subshell. The shell will reinitialize itself in this case, so that the effect will be as if a new shell had been invoked to handle the shell procedure, except that the location of commands located in the parent shell will be remembered by the child. .sp 2 .B Path Search .sp .LP When locating a command, the shell first looks to see if it has a shell function by that name. Then it looks for a builtin command by that name. Finally, it searches each entry in PATH in turn for the command. .LP The value of the PATH variable should be a series of entries separated by colons. Each entry consists of a directory name. The current directory may be indicated by an empty directory name. .LP Command names containing a slash are simply executed without performing any of the above searches. .sp 2 .B Command Exit Status .sp .LP Each command has an exit status that can influence the behavior of other shell commands. The paradigm is that a command exits with zero for normal or success, and non-zero for failure, error, or a false indication. The man page for each command should indicate the various exit codes and what they mean. Additionally, the builtin commands return exit codes, as does an executed function. .sp 2 .B Complex Commands .sp .LP Complex commands are combinations of simple commands with control operators or reserved words, together creating a larger complex command. More generally, a command is one of the following: .nf - simple command - pipeline - list or compound-list - compound command - function definition .fi .LP Unless otherwise stated, the exit status of a command is that of the last simple command executed by the command. .sp 2 .B Pipeline .sp .LP A pipeline is a sequence of one or more commands separated by the control operator |. The standard output of all but the last command is connected to the standard input of the next command. .LP The format for a pipeline is: .nf [!] command1 [ | command2 ...] .fi .LP The standard output of command1 is connected to the standard input of command2. The standard input, standard output, or both of a command is considered to be assigned by the pipeline before any redirection specified by redirection operators that are part of the command. .LP If the pipeline is not in the background (discussed later), the shell waits for all commands to complete. .LP If the reserved word ! does not precede the pipeline, the exit status is the exit status of the last command specified in the pipeline. Otherwise, the exit status is the logical NOT of the exit status of the last command. That is, if the last command returns zero, the exit status is 1; if the last command returns greater than zero, the exit status d221 53 a273 111 .LP Because pipeline assignment of standard input or standard output or both takes place before redirection, it can be modified by redirection. For example: .nf $ command1 2>&1 | command2 .fi sends both the standard output and standard error of command1 to the standard input of command2. .LP A ; or terminator causes the preceding AND-OR-list (described next) to be executed sequentially; a & causes asynchronous execution of the preceding AND-OR-list. .sp 2 .B Background Commands -- & .sp .LP If a command is terminated by the control operator ampersand (&), the shell executes the command asynchronously -- that is, the shell does not wait for the command to finish before executing the next command. .LP The format for running a command in background is: .nf command1 & [command2 & ...] .fi If the shell is not interactive, the standard input of an asynchronous command is set to /dev/null. .sp 2 .B Lists -- Generally Speaking .sp .LP A list is a sequence of zero or more commands separated by newlines, semicolons, or ampersands, and optionally terminated by one of these three characters. The commands in a list are executed in the order they are written. If command is followed by an ampersand, the shell starts the command and immediately proceed onto the next command; otherwise it waits for the command to terminate before proceeding to the next one. .LP ``&&'' and ``||'' are AND-OR list operators. ``&&'' executes the first command, and then executes the second command iff the exit status of the first command is zero. ``||'' is similar, but executes the second command iff the exit status of the first command is nonzero. ``&&'' and ``||'' both have the same priority. .LP The syntax of the if command is .nf if list then list [ elif list then list ] ... [ else list ] fi .fi The syntax of the while command is .nf while list do list done .fi The two lists are executed repeatedly while the exit status of the first list is zero. The until command is similar, but has the word until in place of while repeat until the exit status of the first list is zero. .LP The syntax of the for command is .nf for variable in word... do list done .fi The words are expanded, and then the list is executed repeatedly with the variable set to each word in turn. do and done may be replaced with ``{'' and ``}''. .LP The syntax of the break and continue command is .nf break [ num ] continue [ num ] .fi Break terminates the num innermost for or while loops. Continue continues with the next iteration of the innermost loop. These are implemented as builtin commands. .LP The syntax of the case command is .nf case word in pattern) list ;; ... esac .fi .LP The pattern can actually be one or more patterns (see Shell Patterns described later), separated by ``|'' characters. .LP d275 3 a277 5 .nf (list) .fi d279 3 a281 5 .nf { list; } .fi d283 404 a686 416 .sp 2 .B Functions .sp .LP The syntax of a function definition is .nf name ( ) command .fi .LP A function definition is an executable statement; when executed it installs a function named name and returns an exit status of zero. The command is normally a list enclosed between ``{'' and ``}''. .LP Variables may be declared to be local to a function by using a local command. This should appear as the first statement of a function, and the syntax is .nf local [ variable | - ] ... .fi Local is implemented as a builtin command. .LP When a variable is made local, it inherits the initial value and exported and readonly flags from the variable with the same name in the surrounding scope, if there is one. Otherwise, the variable is initially unset. The shell uses dynamic scoping, so that if you make the variable x local to function f, which then calls function g, references to the variable x made inside g will refer to the variable x declared inside f, not to the global variable named x. .LP The only special parameter than can be made local is ``-''. Making ``-'' local any shell options that are changed via the set command inside the function to be restored to their original values when the function returns. .LP The syntax of the return command is .nf return [ exitstatus ] .fi It terminates the currently executing function. Return is implemented as a builtin command. .sp 2 .B Variables and Parameters .sp .LP The shell maintains a set of parameters. A parameter denoted by a name is called a variable. When starting up, the shell turns all the environment variables into shell variables. New variables can be set using the form .nf name=value .fi .LP Variables set by the user must have a name consisting solely of alphabetics, numerics, and underscores - the first of which must not be numeric. A parameter can also be denoted by a number or a special character as explained below. .sp 2 .B Positional Parameters .sp .LP A positional parameter is a parameter denoted by a number (n > 0). The shell sets these initially to the values of its command line arguments that follow the name of the shell script. The set(1) builtin can also be used to set or reset them. .sp 2 .B Special Parameters .sp .LP A special parameter is a parameter denoted by one of the following special characters. The value of the parameter is listed next to its character. .TP * Expands to the positional parameters, starting from one. When the expansion occurs within a double-quoted string it expands to a single field with the value of each parameter separated by the first character of the IFS variable, or by a if IFS is unset. .TP @@ Expands to the positional parameters, starting from one. When the expansion occurs within double-quotes, each positional parameter expands as a separate argument. If there are no positional parameters, the expansion of @@ generates zero arguments, even when @@ is double-quoted. What this basically means, for example, is if $1 is ``abc'' and $2 is ``def ghi'', then "$@@" expands to the two arguments: "abc" "def ghi" .TP # Expands to the number of positional parameters. .TP ? Expands to the exit status of the most recent pipeline. .TP - (Hyphen) Expands to the current option flags (the single-letter option names concatenated into a string) as specified on invocation, by the set builtin command, or implicitly by the shell. .TP $ Expands to the process ID of the invoked shell. A subshell retains the same value of $ as its parent. .TP ! Expands to the process ID of the most recent background command executed from the current shell. For a pipeline, the process ID is that of the last command in the pipeline. .TP 0 (Zero.) Expands to the name of the shell or shell script. .LP .sp 2 .B Word Expansions .sp .LP This clause describes the various expansions that are performed on words. Not all expansions are performed on every word, as explained later. .LP Tilde expansions, parameter expansions, command substitutions, arithmetic expansions, and quote removals that occur within a single word expand to a single field. It is only field splitting or pathname expansion that can create multiple fields from a single word. The single exception to this rule is the expansion of the special parameter @@ within double-quotes, as was described above. .LP The order of word expansion is: .LP (1) Tilde Expansion, Parameter Expansion, Command Substitution, Arithmetic Expansion (these all occur at the same time). .LP (2) Field Splitting is performed on fields generated by step (1) unless the IFS variable is null. .LP (3) Pathname Expansion (unless set -f is in effect). .LP (4) Quote Removal. .LP The $ character is used to introduce parameter expansion, command substitution, or arithmetic evaluation. .sp 2 .B Tilde Expansion (substituting a user's home directory) .sp .LP A word beginning with an unquoted tilde character (~) is subjected to tilde expansion. All the characters up to a slash (/) or the end of the word are treated as a username and are replaced with the user's home directory. If the username is missing (as in ~/foobar), the tilde is replaced with the value of the HOME variable (the current user's home directory). .sp 2 .B Parameter Expansion .sp .LP The format for parameter expansion is as follows: .nf ${expression} .fi where expression consists of all characters until the matching }. Any } escaped by a backslash or within a quoted string, and characters in embedded arithmetic expansions, command substitutions, and variable expansions, are not examined in determining the matching }. .LP The simplest form for parameter expansion is: .nf ${parameter} .fi The value, if any, of parameter is substituted. .LP The parameter name or symbol can be enclosed in braces, which are optional except for positional parameters with more than one digit or when parameter is followed by a character that could be interpreted as part of the name. If a parameter expansion occurs inside double-quotes: .LP 1) Pathname expansion is not performed on the results of the expansion. .LP 2) Field splitting is not performed on the results of the expansion, with the exception of @@. .LP In addition, a parameter expansion can be modified by using one of the following formats. .sp .TP ${parameter:-word} Use Default Values. If parameter is unset or null, the expansion of word is substituted; otherwise, the value of parameter is substituted. .TP ${parameter:=word} Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. In all cases, the final value of parameter is substituted. Only variables, not positional parameters or special parameters, can be assigned in this way. .TP ${parameter:?[word]} Indicate Error if Null or Unset. If parameter is unset or null, the expansion of word (or a message indicating it is unset if word is omitted) is written to standard error and the shell exits with a nonzero exit status. Otherwise, the value of parameter is substituted. An interactive shell need not exit. .TP ${parameter:+word} Use Alternate Value. If parameter is unset or null, null is substituted; otherwise, the expansion of word is substituted. .LP In the parameter expansions shown previously, use of the colon in the format results in a test for a parameter that is unset or null; omission of the colon results in a test for a parameter that is only unset. .TP ${#parameter} String Length. The length in characters of the value of parameter. .LP The following four varieties of parameter expansion provide for substring processing. In each case, pattern matching notation (see Shell Patterns), rather than regular expression notation, is used to evaluate the patterns. If parameter is * or @@, the result of the expansion is unspecified. Enclosing the full parameter expansion string in double-quotes does not cause the following four varieties of pattern characters to be quoted, whereas quoting characters within the braces has this effect. (UNIMPLEMENTED IN 4.4alpha) .TP ${parameter%word} Remove Smallest Suffix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the smallest portion of the suffix matched by the pattern deleted. .TP ${parameter%%word} Remove Largest Suffix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the largest portion of the suffix matched by the pattern deleted. .TP ${parameter#word} Remove Smallest Prefix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the smallest portion of the prefix matched by the pattern deleted. .TP ${parameter##word} Remove Largest Prefix Pattern. The word is expanded to produce a pattern. The parameter expansion then results in parameter, with the largest portion of the prefix matched by the pattern deleted. .LP .sp 2 .B Command Substitution .sp .LP Command substitution allows the output of a command to be substituted in place of the command name itself. Command substitution occurs when the command is enclosed as follows: .nf $(command) .fi or (``backquoted'' version): .nf `command` .fi .LP The shell expands the command substitution by executing command in a subshell environment and replacing the command substitution with the standard output of the command, removing sequences of one or more s at the end of the substitution. (Embedded s before the end of the output are not removed; however, during field splitting, they may be translated into s, depending on the value of IFS and quoting that is in effect.) .sp 2 .B Arithmetic Expansion .sp .LP Arithmetic expansion provides a mechanism for evaluating an arithmetic expression and substituting its value. The format for arithmetic expansion is as follows: .nf $((expression)) .fi The expression is treated as if it were in double-quotes, except that a double-quote inside the expression is not treated specially. The shell expands all tokens in the expression for parameter expansion, command substitution, and quote removal. .LP Next, the shell treats this as an arithmetic expression and substitutes the value of the expression. .sp 2 .B White Space Splitting (Field Splitting) .sp .LP After parameter expansion, command substitution, and arithmetic expansion the shell scans the results of expansions and substitutions that did not occur in double-quotes for field splitting and multiple fields can result. .LP The shell treats each character of the IFS as a delimiter and use the delimiters to split the results of parameter expansion and command substitution into fields. .sp 2 .B Pathname Expansion (File Name Generation) .sp .LP Unless the -f flag is set, file name generation is performed after word splitting is complete. Each word is viewed as a series of patterns, separated by slashes. The process of expansion replaces the word with the names of all existing files whose names can be formed by replacing each pattern with a string that matches the specified pattern. There are two restrictions on this: first, a pattern cannot match a string containing a slash, and second, a pattern cannot match a string starting with a period unless the first character of the pattern is a period. The next section describes the patterns used for both Pathname Expansion and the case(1) command. .sp 2 .B Shell Patterns .sp .LP A pattern consists of normal characters, which match themselves, and meta-characters. The meta-characters are ``!'', ``*'', ``?'', and ``[''. These characters lose there special meanings if they are quoted. When command or variable substitution is performed and the dollar sign or back quotes are not double quoted, the value of the variable or the output of the command is scanned for these characters and they are turned into meta-characters. .LP An asterisk (``*'') matches any string of characters. A question mark matches any single character. A left bracket (``['') introduces a character class. The end of the character class is indicated by a ``]''; if the ``]'' is missing then the ``['' matches a ``['' rather than introducing a character class. A character class matches any of the characters between the square brackets. A range of characters may be specified using a minus sign. The character class may be complemented by making an exclamation point the first character of the character class. .LP To include a ``]'' in a character class, make it the first character listed (after the ``!'', if any). To include a minus sign, make it the first or last character listed .sp 2 .B Builtins .sp .LP This section lists the builtin commands which are builtin because they need to perform some operation that can't be performed by a separate process. In addition to these, there are several other commands that may be builtin for efficiency (e.g. printf(1), echo(1), test(1), etc). .TP alias [ name[=string] ... ] If name=string is specified, the shell defines the alias ``name'' with value ``string''. If just ``name'' is specified, the value of the alias ``name'' is printed. With no arguments, the alias builtin prints the names and values of all defined aliases (see unalias). .TP bg [ job ] ... Continue the specified jobs (or the current job if no jobs are given) in the background. .TP command command arg... Execute the specified builtin command. (This is useful when you have a shell function with the same name as a builtin command.) .TP cd [ directory ] d688 11 a698 12 If the an entry for CDPATH appears in the environment of the cd command or the shell variable CDPATH is set and the directory name does not begin with a slash, then the directories listed in CDPATH will be searched for the specified directory. The format of CDPATH is the same as that of PATH. In an interactive shell, the cd command will print out the name of the directory that it actually switched to if this is different from the name that the user gave. These may be different either because the CDPATH mechanism was used or because a symbolic link was crossed. .TP \&. file d700 427 a1126 246 .TP eval string... Concatenate all the arguments with spaces. Then re-parse and execute the command. .TP exec [ command arg... ] Unless command is omitted, the shell process is replaced with the specified program (which must be a real program, not a shell builtin or function). Any redirections on the exec command are marked as permanent, so that they are not undone when the exec command finishes. .TP exit [ exitstatus ] Terminate the shell process. If exitstatus is given it is used as the exit status of the shell; otherwise the exit status of the preceding command is used. .TP export name... The specified names are exported so that they will appear in the environment of subsequent commands. The only way to un-export a variable is to unset it. The shell allows the value of a variable to be set at the same time it is exported by writing .nf export name=value .fi With no arguments the export command lists the names of all exported variables. .TP fc [-e editor] [first [last]] .TP fc -l [-nr] [first [last]] .TP fc -s [old=new] [first] The fc builtin lists, or edits and re-executes, commands previously entered to an interactive shell. .RS +.5i .TP 2 -e editor Use the editor named by editor to edit the commands. The editor string is a command name, subject to search via the PATH variable. The value in the FCEDIT variable is used as a default when -e is not specified. If FCEDIT is null or unset, the value of the EDITOR variable is used. If EDITOR is null or unset, ed(1) is used as the editor. .TP 2 -l (ell) List the commands rather than invoking an editor on them. The commands are written in the sequence indicated by the first and last operands, as affected by -r, with each command preceded by the command number. .TP 2 -n Suppress command numbers when listing with -l. .TP 2 -r Reverse the order of the commands listed (with -l) or edited (with neither -l nor -s). .TP 2 -s Re-execute the command without invoking an editor. .TP 2 first .TP 2 last Select the commands to list or edit. The number of previous commands that can be accessed are determined by the value of the HISTSIZE variable. The value of first or last or both are one of the following: .TP 2 [+]number A positive number representing a command number; command numbers can be displayed with the -l option. .TP 2 -number A negative decimal number representing the command that was executed number of commands previously. For example, -1 is the immediately previous command. .TP 2 string A string indicating the most recently entered command that begins with that string. If the old=new operand is not also specified with -s, the string form of the first operand cannot contain an embedded equal sign. .TP The following environment variables affect the execution of fc: .TP 2 FCEDIT Name of the editor to use. .TP 2 HISTSIZE The number of previous commands that are accessable. .RE .TP fg [ job ] Move the specified job or the current job to the foreground. .TP getopts optstring var The POSIX getopts command. .TP hash -rv command... The shell maintains a hash table which remembers the locations of commands. With no arguments whatsoever, the hash command prints out the contents of this table. Entries which have not been looked at since the last cd command are marked with an asterisk; it is possible for these entries to be invalid. .sp With arguments, the hash command removes the specified commands from the hash table (unless they are functions) and then locates them. With the -v option, hash prints the locations of the commands as it finds them. The -r option causes the hash command to delete all the entries in the hash table except for functions. .TP jobid [ job ] Print the process id's of the processes in the job. If the job argument is omitted, use the current job. .TP jobs This command lists out all the background processes which are children of the current shell process. .TP pwd Print the current directory. The builtin command may differ from the program of the same name because the builtin command remembers what the current directory is rather than recomputing it each time. This makes it faster. However, if the current directory is renamed, the builtin version of pwd will continue to print the old name for the directory. .TP read [ -p prompt ] [ -e ] variable... The prompt is printed if the -p option is specified and the standard input is a terminal. Then a line is read from the standard input. The trailing newline is deleted from the line and the line is split as described in the section on word splitting above, and the pieces are assigned to the variables in order. If there are more pieces than variables, the remaining pieces (along with the characters in IFS that separated them) are assigned to the last variable. If there are more variables than pieces, the remaining variables are assigned the null string. .sp The -e option causes any backslashes in the input to be treated specially. If a backslash is followed by a newline, the backslash and the newline will be deleted. If a backslash is followed by any other character, the backslash will be deleted and the following character will be treated as though it were not in IFS, even if it is. .TP readonly name... The specified names are marked as read only, so that they cannot be subsequently modified or unset. The shell allows the value of a variable to be set at the same time it is marked read only by writing .TP readonly name=value With no arguments the readonly command lists the names of all read only variables. .TP set [ { -options | +options | -- } ] arg... The set command performs three different functions. .sp With no arguments, it lists the values of all shell variables. .sp If options are given, it sets the specified option flags, or clears them as described in the section called ``Argument List Processing''. .sp The third use of the set command is to set the values of the shell's positional parameters to the specified args. To change the positional parameters without changing any options, use ``--'' as the first argument to set. If no args are present, the set command will clear all the positional parameters (equivalent to executing ``shift $#''. .TP setvar variable value Assigns value to variable. (In general it is better to write variable=value rather than using setvar. Setvar is intended to be used in functions that assign values to variables whose names are passed as parameters.) .TP shift [ n ] Shift the positional parameters n times. A shift sets the value of $1 to the value of $2, the value of $2 to the value of $3, and so on, decreasing the value of $# by one. If there are zero positional parameters, shifting doesn't do anything. .TP trap [ action ] signal... Cause the shell to parse and execute action when any of the specified signals are received. The signals are specified by signal number. Action may be null or omitted; the former causes the specified signal to be ignored and the latter causes the default action to be taken. When the shell forks off a subshell, it resets trapped (but not ignored) signals to the default action. The trap command has no effect on signals that were ignored on entry to the shell. .TP umask [ mask ] Set the value of umask (see umask(2)) to the specified octal value. If the argument is omitted, the umask value is printed. .TP unalias [-a] [name] If ``name'' is specified, the shell removes that alias. If ``-a'' is specified, all aliases are removed. .TP unset name... The specified variables and functions are unset and unexported. If a given name corresponds to both a variable and a function, both the variable and the function are unset. .TP wait [ job ] Wait for the specified job to complete and return the exit status of the last process in the job. If the argument is omitted, wait for all jobs to complete and the return an exit status of zero. .LP .sp 2 .B Command Line Editing .sp .LP When sh is being used interactively from a terminal, the current command and the command history (see fc in Builtins) can be edited using vi-mode command-line editing. This mode uses commands, described below, similar to a subset of those described in the vi man page. The command set -o vi enables vi-mode editing and place sh into vi insert mode. With vi-mode enabled, sh can be switched between insert mode and command mode. The editor is not described in full here, but will be in a later document. It's similar to vi: typing will throw you into command VI command mode. Hitting while in command mode will pass the line to the shell. @