What Did I Do Wrong in My Bashrc File?

0
7
Asked By CuriousCoder42 On

Years ago, I added a function to my .bashrc that looks like this: `bat () { echo "$(<"$@")" ; }`. Now that I'm back on Linux with a new installation (different distro), I get an error that says `bash: "$@": ambiguous redirect` when I try to use it. I'm confused about what I meant to do. Any insights?

2 Answers

Answered By BashNinja88 On

It seems like the function was meant to read and display multiple files, but it isn't working quite right. The issue is that your implementation might only handle a single argument correctly.

Answered By ScriptSavant99 On

Your original intention seems to be trying to mimic `cat` with just Bash builtins, but this function only works with one argument. If you want to handle multiple files, try this instead:

`bat() { local f; for f in "$@"; do echo "$(<"$f")"; done; }`. That should echo the contents of each file one after the other!

LinuxLover21 -

Haha, that’s a solid fix! Now if only it could also handle stdin like `cat` does!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.