Obviously the other user's response is a valid answer to your problem, but I figured I may as well offer you another solution. First off, to explain the root of your problem in detail: You were just putting a quoted string in the function without actually invoking a function, command, or builtin to actually write your desired text to the terminal. Simple enough. The other user suggested you use echo "STRING"
which is a completely acceptable response.
However, I would suggest alternatively that you use printf
. When writing your scripts it requires a quite different approach to implement printf
than it does to use echo
, but I know many individuals who would argue that getting familiar with printf
is the better option. It may cost being a little trickier to use properly, but it is much more versatile and reliable than echo
. I won't bore you even more by documenting every possible manner of using printf
as there is PLENTY of documentation, guides, and information out there on the subject.
In your specific case, to achieve the same results as the previous response:
function fish_greeting
fish_logo
printf "%s" "Hello Phil. What magic shall we create today?"
end
This will also, like the echo
use case, result in the logo being printed to the terminal via the fish_logo
function that fish_greeting
invoked followed by your string via printf
. A brief explanation of what printf
is doing there:
The first quoted value is acting as the format and the following as the argument. Luckily, printf
supports a variety of format specifiers for different scenarios. In this case the %s
indicates a string, and the argument was passed into that format and written to the terminal output. It's a mouthful... but if you learned anything here then it's totally worth it! And, I personally find it much more rewarding to dig deep in order to garner more experience and knowledge, which will no doubt benefit you in the future.
I'll end this by just showing you a list of printf
's format specifiers to give you a glimpse into how much more useful it is than echo
:
%d: Argument will be used as decimal integer. (signed or unsigned)
%i: Argument will be used as a signed integer.
%o: An octal unsigned integer.
%u: An unsigned decimal integer.
%x or %X: An unsigned hexadecimal integer.
%f, %g or %G: A floating-point number.
%e or %E: A floating-point number in scientific notation.
%s: A string.
%b: A string that interprets backslash escapes.
%% signifies a literal %.
Besides all of those printf
also functions with a large number of recognized backslash escapes, and is just a far superior method of printing than echo
! To wrap this up for sure this time: visit the Fish Shell Documentation, and specifically the section for printf
to learn more.
Fish Shell Docs
Printf Page