How to iterate over array indices in zsh?

In bash we can iterate over index of an array like this

~$ for i in "${!test[@]}"; do echo $i; done

where test is an array, say,

~$ test=(a "b c d" e f)

so that the output looks like

b c d

However, when I do the same in zsh I get an error:

➜ ~ for i in "${!test[@]}"; do echo $i; done
zsh: event not found: test[@]

What is going on?

What is the proper way of iterating over indices in zsh?

Go to Source
Author: Gao Zheng

Getting two different results when ‘cat’ing a file, and ‘cat’ing a file into a variable in zsh?

The file in question is /sys/class/power_supply/BAT0/status.

When I cat it, I receive Full. But when I do status="$(cat /sys/class/power_supply/BAT0/status)" and then echo status, I receive 1 when I want it to output Full. I’m sure I’m just being an idiot and missing something obvious. Any help is appreciated.

Go to Source
Author: LTWood

ls -h command in mac osx Catalina 10.15.2 not working

I’m a newbie and this is probably a very newbie question be forewarned. When using terminal in zsh mode, entering ls -h does not output the expected result. Instead I receive an output as if I just entered ls without the -h. What could be the cause of this? Does ls -h not function the same in zsh mode?

Go to Source
Author: zaddy

How can I configure ZSH to start each shell with an isolated, empty history?

I use ZSH with Oh My Zsh. I would like each new ZSH shell to start with an empty history. Commands typed in one shell should never show up in the history of another shell. How can I achieve this?

I’ve tried appending the following to my ~/.zshrc to no avail:

setopt no_share_history
unsetopt share_history
unsetopt inc_append_history
unsetopt append_history

I have also tried following this answer to make the arrow keys only show local history, but that seemed to have no effect.

Currently, if I open a new shell, it imports history. I cannot seem to delete the history; when I delete ~/.zsh_history, it re-appears with the entire old content once I open a new shell. inc_append_history does prevent history from being written right away, but the history will still eventually be saved once the shell is closed.

Go to Source
Author: bgfvdu3w