As @choroba correctly stated you can't do that, at least not out of the box.
The reason is: the shell will, before executing anything, parse the commandline, This is a process which takes place in several well-defined steps. One of these steps is the "field splitting", where the shell splits the input line into various pieces. Consider:
command arg1 arg2
Somehow the shell has to determine that "command" is the command and "arg1" is the first argument and "arg2" is the second argument, no? There has to be a reason why "arg1" is the first argument and not "arg1 arg2" or why "command" is the command and not "command arg1", etc..
No, having said this, there are two things which influence how this splitting is done: the (shell-)variables IFS and OFS. IFS (the "internal field separator") is a list of characters which - if unmasked will separate fields. In the above example, "arg1" is separated from "arg2" and "command" by a blank - which is part of the IFS.
You can set the IFS yourself to any character (or even an empty string) but per default (stated in the POSIX documents) it is set to "blank", "tab" and "linefeed". For more information see Understanding IFS.
After this rather lengthy general introduction what does that mean for your problem?
You can influence how the field-splitting is done by manipulating the IFS, but you would need to do that before your script is starting, i.e.:
% SAVIFS="$IFS" ; export IFS="" % /path/to/your/script arg1 arg2 ... % IFS="$SAVIFS"
You can do the field splitting inside your script and according to your own rules. For this you capture all the arguments into one string and split that up yourself:
#! /bin/bash chArgs="$*" arg1="" arg1="" [...] shopt -s lastpipe # split the contents of $chArgs here, as an example: echo "$chArgs" | IFS=' ' read arg1 arg2 printf "%s\n%s\n" "$arg1" "$arg2" # OR, just to show how it works: echo "$chArgs" | IFS=',' read arg1 arg2 printf "%s\n%s\n" "$arg1" "$arg2"
Notice, however, that you always need to observe proper quoting when dealing with strings - especially string that could contain characters from the IFS. In your example:
#!/bin/bash var1=$1 var2=$2 echo $var1 echo $var2
This proper quoting is missing and i suppose this is a(n additional) reason why it didn't work as you expected it to work. Try:
#!/bin/bash var1="$1" var2="$2" echo "$var1" echo "$var2"
hi
andcheck1,hello world
and nothi check1,hello
andworld
? How can a machine know that this space is separating the arguments but that space is not? You must provide the input quoted so the shell can know, it cannot guess.void fn(char* a, char* b)
to get"\"yy\", \"zz\""
inb
when invoked asfn("xx", "yy", "zz")
'...'
as a strong quoting operator which in general is preferable for passing literal text (which may contain characters special in the syntax of the shell) as one argument to a command.