Question: I wanted to change the general getchar\_unlocked program to print the position of space when the second number is entered.So i introduced 2 more variables r and a, such that r gets incremented every time a non space character is input and a gets r's value when a space character is input. However, by the change i made only the first no. is getting stored in s and a garbage value is getting stored in a. Why so?

```
   #include <cstdio>
   #define getcx getchar_unlocked
   using namespace std;
   inline void scan( int &n, int &a) //extra parameter a added
  {
    n=0; int r=0;

    char ch;
    ch=getcx();
    while (ch<'0' || ch>'9') //Inclusion of a !=' ' condition 
   {
       if (ch==' ') 
        a=r;
       else
        r++;
      ch=getcx();
   }
   while (ch>='0' &&  ch<='9')
    {
     r++;

     n=10*n + ch -'0';
     ch=getcx();
     }
   }

 int main()
 {

   int t,s,a;
   scan(t,a);
   printf("%d\n",t);

   scan(s,a);
    printf("%d",s); 
   printf("%d",a);
   return 0;
  }

```

Answer: 
This is tricky. When you `source` a script you need to do it in the current shell, not in a sub-shell or child process. Executing `source` from `find` won't work because `find` is a child process, and so changes to environment variables will be lost.

It's rather roundabout, but you can use a loop to parse `find`'s output and run the `source` commands directly in the top-level shell (using [process substitution](http://www.gnu.org/software/bash/manual/bash.html#Process-Substitution)).

```
while read -d $'\0' fileName; do
    source code.sh "$fileName"
done < <(find . -name "*.txt" -type f -print0)

```

Now what's with `-print0` and `-d $'\0'`, you ask? Using these two flags together is a way of making the script extra safe.† File names in UNIX are allowed to contain lots of oddball characters including spaces, tabs, and even newlines. While newlines are rare, they are indeed legal.

`-print0` tells `find` to use NUL characters (`\0`) to separate the file names rather than the default newlines (`\n`). Doing this means file names containing `\n` won't mess up the loop. Using `\0` as a separator works well because `\0` is *not* a legal character in file names.

`-d $'\0'`‡ does the same thing with `read` on the other side. It tells `read` that lines are delimited with `\0` instead of `\n`.

---

† You may have seen this trick before. It's common to write `find ... -print0 | xargs -0 ...` to get the same sort of safety when pairing `find` with `xargs`.

‡ If you're wondering about `$'...'`: that's Bash [ANSI-C quoting](http://www.gnu.org/software/bash/manual/bash.html#ANSI_002dC-Quoting) syntax for writing string literals containing escape codes. Dollar sign plus single quotes. You can write `$'\n'` for a newline or `$'\t'` for a tab or `$'\0'` for a NUL.
You won't be able to use `find` in this way; it will always execute a command in a separate process, not the current shell. If you are using `bash` 4, there's a simple alternative to using `find`:

```
shopt -s globstar
for f in **/*.txt; do
    [[ -f $f ]] && source code.sh "$f"
done

```