Resolved: yargs argument not binding correctly in linux


I am trying to run a node application which uses yargs to read arguments. Following is the code for that.
export class RunCommand {
    public async run(): Promise<string> {
        let commandMap: { [key: string]: any; } = {}
        commandMap['command1'] = new Command1();
        commandMap['command2'] = new Command2();

        const argv = yargs.argv;
        let command = commandMap[argv.command];

        if ( command != null) {
            await command.execute();
        } else {
            if ( argv.command != null ) {
                console.log('Command not found:' + argv.command + '.');
            console.log('Available Commands');
            for(let key in commandMap) {

        return 'Success: ' + argv.command;

let runCommand: RunCommand = new RunCommand();;
I am invoking this command on Amazon linux using a shell script. The shell script looks like this. Filename
export PARAM1=VALUE1
export PARAM2=VALUE2
node RunCommand.js --command command1
Invoking this shell file using ./ should set the two environment variables and then should invoke the RunCommand class with command1 as input to command param.
The terminal is printing following out from console logs.
.ommand not found: command1
Available Commands
If I try to invoke the class directly from the terminal then there is no issue. The respecting command in invoked without any problem.
What could be the issue here? The fullstop in the console log is replacing ‘C’ when I am printing the name of the command.


There was line termination issue. “\r” was getting appended at the end.
Fixed it using sed -i -e 's/\r$//'

If you have better answer, please add a comment about this, thank you!

If you like this answer, you can give me a coffee by <a href=””>click here</a>