By default, a here-doc closing delimiter must start at the very beginning of the line, otherwise it won't be recognized.
Alternatively, if you prefix the opening delimiter with -
, then the closing delimiter may have leading tabs - but only true \t
characters, not spaces.
Note that this also strips leading tabs from the lines of the document itself.
It is unfortunate that bash
offers no option to trim leading spaces (too), given that many editors have the option to insert multiple spaces instead of true tab (\t
) chararacters when the user presses the TAB key.
Since the difference between multiple spaces and genuine tabs:
- is usually not obvious (you typically can't tell by looking at it, as in the question),
- copying and pasting may even quietly convert from tabs to spaces
the more robust solution is NOT to rely on using the -
prefix - sadly, at the expense of readability (depending on how the string is used, leading spaces in the document itself - as opposed to the closing delimiter - may still be acceptable, though):
# ...
for plik in *.tar.gz
do
echo $plik
cat << cmd
user $USER $PASS
cd /centrala/nagrania
put $plik
bye
cmd
done