Search code examples
bashifs

read: A specified flag is not valid for this command


I'm getting this error in a HP-UX machine

    + IFS=; 
    /home/machine1/folder/borrado_de_logs.sh[45]: read: A specified flag is not valid for this command.

And I'm using this code

    head -1 $rutatemporal/logfechas.log > $rutatemporal/cabecera.txt
    cabecera=`cat $rutatemporal/cabecera.txt`
    IFS=';' read -a arreglo<<EOF
    $cabecera
    EOF

In Hp-UX its seems that read -a is not allowed what argument I should use with read?

the content of cabecera.txt is this:

2019-02-01;/home/user/deletelogs/somelog.log

Solution

  • It's probably because -a is not a POSIX compliant flag support for the read command. So it is not surprising that the default shell available in your HP-UX machine is not supporting it.

    You can still use the read command without -a to split and store on individual variable names as below. Also you don't need a here-doc to read from the input file, but rather use the read command directly on the file itself

    IFS=\; read -r date path < "$rutatemporal"/cabecera.txt
    echo "$date"
    echo "$path"