I'm using stat and for some reason it works on one my of my servers running the newer version of bash but not on the older version. Of course the errors are really generic, but they're coming from the following code block:

while IFS='' read -r line || [[ -n $line ]]; do
IFS=' ' read size file <<< $line
containsElement "$(stat -c %U $file)" "${users[@]}"
if [ $(echo $?) == "1" ] ; then
    rm -f $DU_SAVE-$(stat -c %U $file)_du.txt
    users+=("$(stat -c %U $file)")

echo $line >> $DU_SAVE-$(stat -c %U "$file")_du.txt
done < "${DU_SAVE}_du.txt"

The program use isn't all that important but it grabs the user information from a DU command previously saved to file and adds them to a list. Where the errors are:

stat: missing operand Try stat --help' for more information. stat: cannot stat': No such file or directory

Over each file.

Edit: I've noticed the read command is what's messing up stat, the exact same code works perfectly on a newer bash version, perhaps I'm wording it wrong.

  • I'm reasonably sure <<< is not a valid construct in bash 3.2. – lcd047 Jul 20 '15 at 16:08
  • 2
    @lcd047 It is, that feature appeared in bash 2.05b. – Gilles Jul 20 '15 at 23:20
  • 1
    If the input is a du command, the size is followed by a tab. Is that a space or a tab in IFS=' ' read …? Why not while read -r size file … — this will work just as well as your attempt to split? – Gilles Jul 20 '15 at 23:21
  • I tried that @Gilles . Ah really? I'm new to Bash relatively, so I'm still learning a lot of things, though I have experience with several other languages so it's not 'too hard'. Thanks. – insidesin Jul 21 '15 at 8:19

Of course I spend a while on getting the solution then decide to ask on here and solve it within 10minutes of asking on here... I do that a lot.

The solution was that my variable splitting command just simply did not want to work on this version of bash so I instead just resorted to cut with a delimiter of ' ' :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.