Storing credentials in plain text is always a tricky case, it depends on case-by-case. The main rule is: never store the password inside the script.
If the script will run only manually (someone executing the script), do not store the password on the script, instead, make the script ask the password every time it's executed.
If the script will run automatically:
- Create a specific user for the purpose you need. ensure the user has the minimum permissions as possible. Ensure the user does not have access to any other file and does not have permission to execute anything else other than the script you need.
- Create a file containing the password and make the script read from this file. Make sure this password file cannot be read from anyone else.
- Is passwords the only way to authenticate? Some applications support private/public keys. If you can, use it. Make sure the private key is secure.
- Keep in mind that the chances of those credentials getting compromised are increased just by the fact you have them stored. Having that in mind, plan mitigation actions, for example, ensure the account has the minimum permissions as possible, ensure the account can only log in from a specific server, implement a log monitoring tool (or a SIEM) to get alerted when this account is used.
There's a very good article on the unix stack exchange about this topic, i do recommend you checking it out before implementing any script with passwords.