@@ -212,6 +212,12 @@ prop_checkBashisms118 = verify checkBashisms "#!/bin/busybox sh\nxyz=1\n${!x*}"
212
212
prop_checkBashisms119 = verify checkBashisms " #!/bin/busybox sh\n x='test'\n ${x^^[t]}" -- SC3059
213
213
prop_checkBashisms120 = verify checkBashisms " #!/bin/sh\n [ x == y ]"
214
214
prop_checkBashisms121 = verifyNot checkBashisms " #!/bin/sh\n # shellcheck shell=busybox\n [ x == y ]"
215
+ prop_checkBashisms122 = verify checkBashisms " #!/bin/dash\n $'a'"
216
+ prop_checkBashisms123 = verifyNot checkBashisms " #!/bin/busybox sh\n $'a'"
217
+ prop_checkBashisms124 = verify checkBashisms " #!/bin/dash\n type -p test"
218
+ prop_checkBashisms125 = verifyNot checkBashisms " #!/bin/busybox sh\n type -p test"
219
+ prop_checkBashisms126 = verifyNot checkBashisms " #!/bin/busybox sh\n read -p foo -r bar"
220
+ prop_checkBashisms127 = verifyNot checkBashisms " #!/bin/busybox sh\n echo -ne foo"
215
221
checkBashisms = ForShell [Sh , Dash , BusyboxSh ] $ \ t -> do
216
222
params <- ask
217
223
kludge params t
@@ -229,7 +235,8 @@ checkBashisms = ForShell [Sh, Dash, BusyboxSh] $ \t -> do
229
235
230
236
bashism (T_ProcSub id _ _) = warnMsg id 3001 " process substitution is"
231
237
bashism (T_Extglob id _ _) = warnMsg id 3002 " extglob is"
232
- bashism (T_DollarSingleQuoted id _) = warnMsg id 3003 " $'..' is"
238
+ bashism (T_DollarSingleQuoted id _) =
239
+ unless isBusyboxSh $ warnMsg id 3003 " $'..' is"
233
240
bashism (T_DollarDoubleQuoted id _) = warnMsg id 3004 " $\" ..\" is"
234
241
bashism (T_ForArithmetic id _ _ _ _) = warnMsg id 3005 " arithmetic for loops are"
235
242
bashism (T_Arithmetic id _) = warnMsg id 3006 " standalone ((..)) is"
@@ -321,7 +328,11 @@ checkBashisms = ForShell [Sh, Dash, BusyboxSh] $ \t -> do
321
328
322
329
bashism t@ (T_SimpleCommand _ _ (cmd: arg: _))
323
330
| t `isCommand` " echo" && argString `matches` flagRegex =
324
- if isDash
331
+ if isBusyboxSh
332
+ then
333
+ when (not (argString `matches` busyboxFlagRegex)) $
334
+ warnMsg (getId arg) 3036 " echo flags besides -n and -e"
335
+ else if isDash
325
336
then
326
337
when (argString /= " -n" ) $
327
338
warnMsg (getId arg) 3036 " echo flags besides -n"
@@ -330,6 +341,7 @@ checkBashisms = ForShell [Sh, Dash, BusyboxSh] $ \t -> do
330
341
where
331
342
argString = concat $ oversimplify arg
332
343
flagRegex = mkRegex " ^-[eEsn]+$"
344
+ busyboxFlagRegex = mkRegex " ^-[en]+$"
333
345
334
346
bashism t@ (T_SimpleCommand _ _ (cmd: arg: _))
335
347
| getLiteralString cmd == Just " exec" && " -" `isPrefixOf` concat (oversimplify arg) =
@@ -443,10 +455,10 @@ checkBashisms = ForShell [Sh, Dash, BusyboxSh] $ \t -> do
443
455
(" hash" , Just $ if isDash then [" r" , " v" ] else [" r" ]),
444
456
(" jobs" , Just [" l" , " p" ]),
445
457
(" printf" , Just [] ),
446
- (" read" , Just $ if isDash then [" r" , " p" ] else [" r" ]),
458
+ (" read" , Just $ if isDash || isBusyboxSh then [" r" , " p" ] else [" r" ]),
447
459
(" readonly" , Just [" p" ]),
448
460
(" trap" , Just [] ),
449
- (" type" , Just [] ),
461
+ (" type" , Just $ if isBusyboxSh then [ " p " ] else [] ),
450
462
(" ulimit" , if isDash then Nothing else Just [" f" ]),
451
463
(" umask" , Just [" S" ]),
452
464
(" unset" , Just [" f" , " v" ]),
0 commit comments