8
votes
Accepted
How to make '.zshrc' to search for sourced files in the specific folder and not in the folder from which the terminal has been opened
Give an absolute path to the file:
. ~/system-wide-clipboard.zsh
7
votes
To check whether first or last character of a string is x
In any POSIXy shell, the case statement provides pattern matches (without running any external tools):
isx() {
case $1 in
x ) printf '%s\n' "'$1' is just a single x";;
x*...
4
votes
Accepted
incrementing file names in zsh
This may be easier with zshs powerful globbing syntax instead of find and wc. Try this:
#!/usr/bin/env zsh
setopt extendedglob
nextFilename() {
local fqp=${1:?}
local -a fileCopies=( ${fqp:r}(...
4
votes
Accepted
To check whether first or last character of a string is x
Your expansion with ${ .. } does not run any code: it just produces a text string which is itself not even a valid command (it would need an echo, and also round brackets).
There is a Bash expansion ...
3
votes
Accepted
To execute a shell script: Using "zsh script.sh" and using "./script.sh"
That’s as expected! By default, your file script.sh is not going to be executable. You can correct this with:
chmod +x ./script.sh
Then running ./script.sh should work. (You can change it back with ...
2
votes
To check whether first or last character of a string is x
Since you're asking for zsh, you can of course use standard:
case $string in
(x* | *x) echo "starts or ends in x (or both)";;
(*) echo "Neither starts nor ends in x";;
esac
...
2
votes
To check whether first or last character of a string is x
To address your "What is the problem here?" question:
string="2x3"
if [[ "${-n $string | head -c 1}" == "x" ]]; then
echo "first character is x"
...
Community wiki
2
votes
Be notified of new mail in any Maildir inbox under ~/Mail, in the Zsh shell
Since Maildir mailboxes are used, new mail may be found by looking for any regular file in any directory called new under ~/Mail. We ignore the fact that for a directory to be a legal Maildir mailbox, ...
2
votes
zsh alias does not complete fully if not sourced once a day
If you have some sort of personal configuration file that isn't standard, such as this ~/.zsh you mention, of course you need to source it manually each time you log in. To make this happen ...
1
vote
Zsh script to filter array excluding a substring
prd~uat matches any string that is prd and is not uat. So that's the same as prd alone.
*prd~uat*east* matches any string that ends in prd and that does not start with uat followed by something that ...
1
vote
Accepted
Zsh script to filter array excluding a substring
Putting the match and exclude filters into a parenthesized group appears to work:
#!/usr/bin/env zsh
# arg1, environment: dev qa uat-prd prd
# arg2, region: east west *
filterServerArray() {
# ...
1
vote
In bash/zsh, how to compare the metadata in two directories including . and excluding .. and the contents inside subdirectories?
-a lists all directory entries, that includes . and .. on systems where readdir() / getdents*() include them. Here, you could run ls twice, once for . with -d (ls -ld . will work even on systems where ...
1
vote
In bash/zsh, how to compare the metadata in two directories including . and excluding .. and the contents inside subdirectories?
Presumably you're using GNU ls, in which you can omit only .. by using the --ignore/-I option:
% ls -la --full-time
total 12
drwxr-xr-x 3 muru muru 4096 2024-06-25 11:14:18.165432064 +0900 .
drwxr-xr-...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
zsh × 3032bash × 576
shell × 530
autocomplete × 319
shell-script × 300
oh-my-zsh × 268
macos × 179
terminal × 158
command-history × 155
command-line × 126
wildcards × 124
alias × 116
prompt × 114
linux × 84
tmux × 74
environment-variables × 73
function × 65
keyboard-shortcuts × 62
ssh × 54
scripting × 54
path × 54
colors × 50
zle × 48
quoting × 44
pipe × 43