twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
1.06k stars 67 forks source link

Bash commands not working as they do in my terminal (running on mac) #284

Open RobertMcKiernan opened 1 year ago

RobertMcKiernan commented 1 year ago

In my execute code settings, I've set the shell path to /bin/zsh, which is the same as my terminal.

I've written this tiny script to print out the dates for the month to use as headers in my todo notes.

echo "generate dates for month"
for x in $(seq -w 01 31)
do
    date --date "2307$x" "+%A %F"
done

This works fine when I run the file from my terminal, but I get the following output if I execute it in a code block in obsidian.

generate dates for month
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
...

I also tried to use gdate instead, which again, runs fine in my terminal, but when I run it in the code snippet it give me this error:

/var/folders/zj/2lw2sfsx6hg0cd3n_cm6v1_r0000gn/T/temp_1690630579172.sh:10: command not found: gdate

These commands give the same output whether I'm in my terminal, or running code in obsidian:

whoami
> myusername
echo $SHELL
> /bin/zsh

I thought it could be a permissions issue. This works fine in my terminal though:

cd /var/folders/zj/2lw2sfsx6hg0cd3n_cm6v1_r0000gn/T/
touch tmp_test.sh
echo "gdate" >tmp_test.sh
chmod +x tmp_test.sh
./tmp_test.sh
> Sat Jul 29 12:46:28 BST 2023

and besides, the echo bit of the script prints out, so I don't think it's that (although I don't know how the temp files are used in this plugin)

Any clues on where I can dig next? Cheers

holroy commented 7 months ago

This sound like a path issue. Your terminal and the code block don't have the same path settings. Try doing echo $PATH in both environments and see if/how they differ. To correct you need to identify which login scripts are used in either case, and possibly change them to make them match.