I'm writing a bash script that needs to both be able to cd
in the current shell and use less
to display longform text. To be able to cd
, I understand that I need to source
the script when I call it, which I've done via an alias in my ZSH config. However, when I do this, less
breaks: instead of echo -e "$result" | less
displaying its usual scrolling buffer, the long text gets dumped into the shell.
For context, this is a bash script acting as a wrapper for a Node.js script so as to be able to have native access to bash commands (like cd
, open
, etc.). The alias in my zshrc is as follows (with the path truncated): alias bk='source ~/.../bookmark/bookmark.sh'
.
Is there any way to satisfy both the need to cd
and the need to use less
?
Fixed! This turned out to be an issue in my script's logic. I was using condition=$(echo $result | cut -c 1-3)
, but in reality need the first three characters (not columns) of $result
, which I then did by using $result | head -c 3
. What's interesting about this is that fetching the first three columns from $result
when determined by running ./bookmark.sh
works as an equivalent to fetching the first three characters, but running the alias yields the issue here.