Home > other >  Passing a ' character as a command line argument seems to start a prompt in C on Ubuntu
Passing a ' character as a command line argument seems to start a prompt in C on Ubuntu

Time:01-12

hope someone can help.

I'm working on a problem set passing arguments in C99 on Ubuntu, part of the problem set specifies that non-integer characters should lead to an early return from the main function and program termination.

For example:

#include <stdio.h>

int main(int argc, string argv[])
{
    // code
}

I've discovered that if I pass the program a ' character at the end of a series of digits e.g. ./runme 12345' it seems to open some kind of shell/prompt.

Can anyone help with what this is?

CodePudding user response:

This is not related to C, but to your shell. In bash, a single quote has special meaning to the shell, and if you want to pass it to some other program, you have to quote it, for instance

./runme 12345\'

or

./runme "12345'"

This applies of course to all shell meta-characters.

CodePudding user response:

As John3136 wrote in a comment:

It's the shell interpreting the quote and expecting you to enter more stuff then a clo[s]ing quote.

  • Related