My shell script (see below) is failing partway through execution with "/bin/sh: 1: Syntax error: Bad fd number." This thread suggests that the problem is using the >& construction in sh, which in Ubuntu is linked to dash, which does not support >&. I am puzzled, because while the error message suggests that my script is running in sh, I am pretty confident that it is running in bash:
- The login shell from which I am executing it is bash, as indicated by echo $0.
- The first line of the script is #!/bin/bash
- If I insert readlink /proc/$$/exe into my script (as suggested here), the output is /usr/bin/bash.
- Both /bin/bash and /usr/bin/bash are actual executables, not links to other files.
So, if I'm wrong and it's actually running in sh, why is it doing so? And if it is actually running in bash, why is it returning an error when that syntax is supposed to work in bash?
I'm running this in Ubuntu 22.04 using a 6.5.0-28 kernel.
Any feedback is appreciated.
The purpose of this script is to create a multipart tar (using this method) from a list of files and directories in a text file, capping the part size at 512 Gb. This should generate four files, but it consistently fails after the third part:
#!/bin/bash
tar -cvf /home/me/archive.tar --multi-volume --tape-length=512000 --new-volume-script='echo -n "/home/me/archive-${TAR_VOLUME}.tar" >&${TAR_FD}' --exclude-tag-all=donotcopy --exclude-backups -T /home/me/file-list.txt
The full error text at failure is:
bin/sh: 1: Syntax error: Bad fd number
tar: ‘echo -n "/home/me/archive-${TAR_VOLUME}.tar" >&${TAR_FD}’ command failed
tar: Error is not recoverable: exiting now
The format of file-list.txt is as follows:
/home/me/foo
/home/me/bar/file-1.xyz
/home/me/bar/file-2.xyz
$!/bin/bash
a copy/paste typo. likewise--tape-length
(not--tape=length
). I couldn't reproduce the error, command wotk fine under bash login, spliting file as expected.