Context
truffle exec runs a script inside the Truffle environment but does not forward arbitrary CLI flags to your script — only Truffle's own options like --network are parsed. You can read raw arguments from process.argv and parse them yourself with yargs-parser, which leaves Truffle's built-in flags untouched.
Usage
const argv = require("yargs-parser")(process.argv.slice(2));
module.exports = async (callback) => {
const name = argv?.n || "World";
callback(`Hello ${name}`);
};
truffle exec hello.js -n=Dung --network development
-n=Dung: Custom argument--network: Standard Truffle option (still works)