il file a.txt ha due righe vuote alla fineCome mantenere righe vuote alla fine di un file quando comando cat utente che ho in script di shell
[[email protected] tmp]$ cat -n a.txt
1 jhasdfj
2
3 sdfjalskdf
4
5
e il mio script è:
[[email protected] tmp]$ cat t.sh
#!/bin/sh
a=`cat a.txt`
a_length=`echo "$a" | awk 'END {print NR}'`
echo "$a"
echo $a_length
[[email protected] tmp]$ sh t.sh
jhasdfj
sdfjalskdf
3
aperta di debug
[[email protected] tmp]$ sh -x t.sh
++ cat a.txt
+ a='jhasdfj
sdfjalskdf'
++ echo 'jhasdfj
sdfjalskdf'
++ awk 'END {print NR}'
+ a_length=3
+ echo 'jhasdfj
sdfjalskdf'
jhasdfj
sdfjalskdf
+ echo 3
3
il comando cat rubare le righe vuote alla fine del file.How per risolvere questo problema.