@@ -0,0 +1,31 @@
|
||||
/** Shared helpers for drive-resident /bin scripts (prepended before each command). */
|
||||
function bareStdin(ctx) {
|
||||
return typeof ctx.shellStdin === 'string' ? ctx.shellStdin : ''
|
||||
}
|
||||
|
||||
async function run(ctx, argv) {
|
||||
const args = argv.slice(1).filter((a) => !a.startsWith('-'))
|
||||
let a = 1
|
||||
let step = 1
|
||||
let b = 1
|
||||
if (args.length === 1) {
|
||||
b = parseInt(args[0], 10)
|
||||
} else if (args.length === 2) {
|
||||
a = parseInt(args[0], 10)
|
||||
b = parseInt(args[1], 10)
|
||||
} else if (args.length >= 3) {
|
||||
a = parseInt(args[0], 10)
|
||||
step = parseInt(args[1], 10)
|
||||
b = parseInt(args[2], 10)
|
||||
}
|
||||
if (step === 0 || Number.isNaN(a) || Number.isNaN(b) || Number.isNaN(step)) {
|
||||
ctx.console.error('seq: invalid arguments')
|
||||
ctx.exitCode = 1
|
||||
return
|
||||
}
|
||||
if (step > 0) {
|
||||
for (let x = a; x <= b; x += step) ctx.console.log(String(x))
|
||||
} else {
|
||||
for (let x = a; x >= b; x += step) ctx.console.log(String(x))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user