}
#endif
+static char **skip_dash_dash(char **argv)
+{
+ argv++;
+ if (argv[0] && argv[0][0] == '-' && argv[0][1] == '-' && argv[0][2] == '\0')
+ argv++;
+ return argv;
+}
+
static int FAST_FUNC builtin_eval(char **argv)
{
int rcode = EXIT_SUCCESS;
- if (*++argv) {
+ argv = skip_dash_dash(argv);
+ if (*argv) {
char *str = expand_strvec_to_string(argv);
/* bash:
* eval "echo Hi; done" ("done" is syntax error):
static int FAST_FUNC builtin_cd(char **argv)
{
- const char *newdir = argv[1];
+ const char *newdir;
+
+ argv = skip_dash_dash(argv);
+ newdir = argv[0];
if (newdir == NULL) {
/* bash does nothing (exitcode 0) if HOME is ""; if it's unset,
* bash says "bash: cd: HOME not set" and does nothing
static int FAST_FUNC builtin_exec(char **argv)
{
- if (*++argv == NULL)
+ argv = skip_dash_dash(argv);
+ if (argv[0] == NULL)
return EXIT_SUCCESS; /* bash does this */
/* Careful: we can end up here after [v]fork. Do not restore
*/
/* note: EXIT trap is run by hush_exit */
- if (*++argv == NULL)
+ argv = skip_dash_dash(argv);
+ if (argv[0] == NULL)
hush_exit(G.last_exitcode);
/* mimic bash: exit 123abc == exit 255 + error msg */
xfunc_error_retval = 255;
/* bash: exit -2 == exit 254, no error msg */
- hush_exit(xatoi(*argv) & 0xff);
+ hush_exit(xatoi(argv[0]) & 0xff);
}
static void print_escaped(const char *s)
"------------------\n");
for (x = bltins1; x != &bltins1[ARRAY_SIZE(bltins1)]; x++) {
if (x->b_descr)
- printf("%s\t%s\n", x->b_cmd, x->b_descr);
+ printf("%-10s%s\n", x->b_cmd, x->b_descr);
}
bb_putchar('\n');
return EXIT_SUCCESS;
static int FAST_FUNC builtin_shift(char **argv)
{
int n = 1;
- if (argv[1]) {
- n = atoi(argv[1]);
+ argv = skip_dash_dash(argv);
+ if (argv[0]) {
+ n = atoi(argv[0]);
}
if (n >= 0 && n < G.global_argc) {
if (G.global_args_malloced) {
smallint sv_flg;
#endif
- arg_path = NULL;
- filename = *++argv;
+ argv = skip_dash_dash(argv);
+ filename = argv[0];
if (!filename) {
/* bash says: "bash: .: filename argument required" */
return 2; /* bash compat */
}
+ arg_path = NULL;
if (!strchr(filename, '/')) {
arg_path = find_in_path(filename);
if (arg_path)
mode_t mask;
mask = umask(0);
- if (argv[1]) {
+ argv = skip_dash_dash(argv);
+ if (argv[0]) {
mode_t old_mask = mask;
mask ^= 0777;
- rc = bb_parse_mode(argv[1], &mask);
+ rc = bb_parse_mode(argv[0], &mask);
mask ^= 0777;
if (rc == 0) {
mask = old_mask;
* bash: umask: 'q': invalid symbolic mode operator
* bash: umask: 999: octal number out of range
*/
- bb_error_msg("%s: '%s' invalid mode", argv[0], argv[1]);
+ bb_error_msg("umask: '%s' invalid mode", argv[0]);
}
} else {
rc = 1;
int ret = EXIT_SUCCESS;
int status, sig;
- if (*++argv == NULL) {
+ argv = skip_dash_dash(argv);
+ if (argv[0] == NULL) {
/* Don't care about wait results */
/* Note 1: must wait until there are no more children */
/* Note 2: must be interruptible */