I am using the command below in my expect script (in tcl/Tk) for checking whether the entered path is an individual file or directory:set b [exec ./check.sh $file1 | awk -F {=} {{print $1}} ]The above command invokes check.sh file. Its contents are:#!/bin/bashif [[ -f $1 ]] then    echo Fileelse    if [[ -d $1 ]]     then        echo Directory    else         echo Other    fifiThe command runs fine. The problem occurs when I am using the command in three parallel running scripts(the three scripts are same) it gives me an errorerror writing stdout: bad file numberbecause the three scripts are invoking the same file at the same time.So, can anyone help me with this?Here's my script:----#!/usr/bin/expect#Set the timeout time for expect commandset timeout 5#First Argument is Ip Addressset ip [lindex $argv 0]#Seond Argument is UserNameset user [lindex $argv 1]#Third Argument is Passwordset password [lindex $argv 2]#Fourth Argument is Path to the source File to be copied (Keeping in mind that this path is concatenated with the second path in the program)set file1 [lindex $argv 3]#Fifth Argument is the destination pathset file2 [lindex $argv 4]#Fetches the epoch time by executing time scriptset t1 [exec ./time | awk -F {=} {{print $1}} ]#Checks whether the path to copied is an individual file or a directoryset b [exec ./check.sh $file1 | awk -F {=} {{print $1}} ]if { $b == File } {    puts It is a file    #Executes the scp command    spawn bash -c scp -p $file1 $user@$ip:$file2    #Sends the password    expect password:    send $password\r;    interact    puts Number of Files Copied: 1}if { $b == Directory } {    puts It is a directory;    #Executes the scp command    spawn bash -c scp -r -p $file1 $user@$ip:$file2    #Sends the password    expect password:    send $password\r;    interact    #For calculating the number of files copied    set c [exec find $file1 -type f | wc -l | awk -F {=} {{print $1}}]    puts Number of Files Copied: $c\n}
How to check whether a given path is a file or directory
linux;shell script;expect;tcl