1

I have recently upgraded from bash 4.2.46 to bash version 4.2.50

I had a script with the line:

mapfile -t my_array < <(grep ${ID} -w /etc/passwd | cut -d ":" -f 1,4,5)

where ID is an arbitrary integer we'd like to look for in the file passwd and then load all results into an array.

that used to work but now throws an error

usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] -e pattern_list...
        [-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] [-e pattern_list...]
        -f pattern_file... [file...]

can anyone explain how to work around this depreciation? I have attempted using sed and awk however the issue seems to be the format of my output redirection.

the text file passwd looks like this name:garbageData:garbageData:ID:password

0

1 Answer 1

2

You would get that error if you executed the script with ksh instead of with bash; either the sh-bang header line incorrectly points to ksh, or it points to /bin/sh which is ksh on AIX, or you're explicitly calling it as ksh /the/script.

ksh does not support mapfile nor with versions prior to ksh93t+, the <( ...) process substitution syntax when used as the target of a redirection, such as <. Clarification provided by Stéphane Chazelas.

Fix the sh-bang line to call bash (or explicitly invoke bash instead of ksh, if that's the case).

Additionally, the grep command is complaining because you've put an argument before all of the options; rearrange the grep to be:

grep -w "${ID}" /etc/passwd

(also quoting the variable expansion).

8
  • Thank you for the response; I am currently using #!/bin/bash as my shebang line and upon further investigation I believe I am using it correctly. However your solution lead me down a rabbit hole explaining the difference between "bash /the/script" and "./script" which has yielded another error, so I'll update the question :)
    – CyberStems
    Commented Nov 4, 2019 at 15:54
  • Is /bin/bash a link to /bin/ksh, for some reason?
    – Jeff Schaller
    Commented Nov 4, 2019 at 15:56
  • I do not believe so as my /bin directory contains both ksh and bash. Is there another definitive way I can tell?
    – CyberStems
    Commented Nov 4, 2019 at 16:01
  • @CyberStems run ls -i /bin/bash /bin/ksh* and see if the numbers on the left are the same; or ls -l /bin/bash and see if it's a symlink.
    – Jeff Schaller
    Commented Nov 4, 2019 at 16:08
  • in the first command the numbers differ, and the second command outputs /bin/bash -> ../opt/freeware/bin/bash so I don't think it is a symlink. Once again your extensive help is greatly appreciated!
    – CyberStems
    Commented Nov 4, 2019 at 16:14

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.