A way to prevent bash from parsing command line w/out using escape symbols

后端 未结 3 1939
离开以前
离开以前 2021-01-17 06:04

I\'m looking for a way (other than \".\", \'.\', \\.) to use bash (or any other linux shell) while preventing it from parsing parts of command line. The problem seems to be

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-17 06:44

    Your spec still isn't very clear. As far as I know the problem is you want to completely reinvent how the shell handles arguments. So… you'll have to write your own shell. The basics aren't even that difficult. Here's pseudo-code:

    while true:
        print prompt
        read input
        command = (first input)
        args = (argparse (rest input))
        child_pid = fork()
        if child_pid == 0: // We are inside child process
            exec(command, args) // See variety of `exec` family functions in posix
        else: // We are inside parent process and child_pid is actual child pid
            wait(child_pid) // See variety of `wait` family functions in posix
    

    Your question basically boils down to how that "argparse" function is implemented. If it's just an identity function, then you get no expansion at all. Is that what you want?

提交回复
热议问题