What Did I Mean by This Bash Function in My .bashrc?

0
13
Asked By QuirkyPenguin42 On

I added a line to my .bashrc ages ago and I can't remember what I was trying to achieve. The line is:

bat () { echo "$(<"$@")" ; }

Now I've installed a different Linux distro and when I run it, I get the error:

bash: "$@": ambiguous redirect

Can anyone help me understand what I might have intended with this?

2 Answers

Answered By SillySyntax On

Looks like you were trying to implement `cat` using just Bash builtins! However, your function only accepts one argument. If you want to handle multiple files, you’d need to use a loop like this:

bat() { local f; for f in "$@"; do echo "$(<"$f")"; done; }

Answered By CodeWanderer88 On

It seems like you were trying to create a version of `cat` that can handle multiple files, but it didn’t really work out as expected. Your function only processes one filename at a time, which is why you're running into that error when you try to pass multiple arguments.

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.