Open sim4life opened 3 weeks ago
Hi @sim4life ,
Although I am not very familiar with Nushell, I just tried executing the command you provided directly in Nushell
~> for dir in "ls -s . | where type == dir | get name"; do echo $dir; done 1 06/07/2024 06:00:29 PM
Error: nu::parser::keyword_missing_arg
Γ Missing argument to `in`.
ββ[entry #21:1:11]
1 β for dir in "ls -s . | where type == dir | get name"; do echo $dir; done
Β· β²
Β· β°ββ missing any value that follows in
β°ββββ
I don't think it is a valid nushell script
Check https://www.nushell.sh/book/control_flow.html#for for a valid for loop sytax in nushell
for file in (ls .) {
print $file
}
for direc in (ls -s . | where type == dir | get name) {
print $direc
}
set shell
applies to the shell used for linewise recipes as well as backticks.
So when you set the shell to Nushell, you should write recipe lines in Nushell as well.
If you want to mix Bash and Nushell recipes, set shell
to one and use shebang recipes for the other.
If you want to mix Bash and Nushell in the same recipe, you need to call out explicitly from one to the other. You could do this indirectly through just:
set shell := ['nu', '-c']
# Nu script
list-dir-names:
ls -s . | where type == dir | get name
# Bash script
for:
#!/usr/bin/env bash
set -euxo pipefail
for direc in $(just list-dir-names); do echo $direc; done
I don't see a reason to ever do this, but it is possible.
Thanks for the replies: The syntax
for3:
for direc in (ls -s . | where type == dir | get name) { echo $direc }
was giving me an error:
for3: -c: line 1: syntax error near unexpected token `('
I did NOT intend to mix n match nushell and bash syntax but it seems that the backticks shell command syntax ignores rest of the global shell settings in justfile and chooses bash in Windows. So I ended up completely replacing justfile for-loop syntax with nushell for-loop syntax like:
for2:
#!nu
ls -s . | where ($it | $it.type == dir) | get name
Can you post a complete justfile, along with the error message you're getting? I want to make sure I understand the problem.
One clarification to my previous comment: backticks within a recipe line are not preprocessed by just in any way. They are interpreted by the shell normally. So backticks in bash will execute the enclosed command in a subshell, while backticks in Nu just indicate a string.
The only syntax that causes just to change the text of a recipe is {{ }}
. After those substitutions are made, the resulting script is interpreted by the shell directly.
@sim4life
Are you referencing the for loop section in the readme and you think you are using a justfile for loop syntax?
for2:
for direc in `ls -s . | where type == dir | get name`; do \
echo $direc; \
done
with your above justfile, you are expecting that
the for is a generic justfile loop
the backticks will be executed in nushell, and then the output being processed in the for loop
right?
but the for loop section in the readme is actually describing how to write a multi-line constructs in the justfile, and it is taking bash as an example. (which means there is no justfile-syntax for loop, the example is bash for loop)
set shell := ['nu', '-c']
, the whole recipe is processed in nushell, then the for loop
syntax is wrong, as it is actually a bash forset shell := ['nu', '-c']
, the whole recipe is processed in bash, then the command ls -s . | where type == dir | get name
will be processed in bashso, you are trying use so-called "justfile-syntax" for loop and nu command in backticks. However, it is actually mixing a bash for-loop and a nushell command in the backticks.
@casey @starthal Please correct me if I am wrong
Using the alacritty v0.13.2 terminal, I'm trying to write Nushell v0.93.0 specific commands in my justfile on Windows 11 23H2. My justfile looks like:
$ just for
$ just for2
It seems that justfile is interpreting
ls -s . | where type == dir | get name
as a bash command when I want it to be interpreted as Nushell command. If I start myjustfile
withset shell := ["nu", "-c"]
ORset shell := ["nu", "--env-config", "~\\.config\\nushell\\env.nu", "--config", "~\\.config\\nushell\\config.nu", "-c"]
OR I change the recipe to:then it reports the following error:
Any suggestions on setting up windows and Nushell cross-platform justfile scripting?