Skip to main content
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
Stephen Kitt's user avatar
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*...
ilkkachu's user avatar
  • 141k
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}(...
Gairfowl's user avatar
  • 650
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 ...
Paul_Pedant's user avatar
  • 9,074
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 ...
wobtax's user avatar
  • 318
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 ...
Stéphane Chazelas's user avatar
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" ...
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, ...
Kusalananda's user avatar
  • 339k
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 ...
terdon's user avatar
  • 245k
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 ...
Stéphane Chazelas's user avatar
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() { # ...
Gairfowl's user avatar
  • 650
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 ...
Stéphane Chazelas's user avatar
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-...
muru's user avatar
  • 73.9k

Only top scored, non community-wiki answers of a minimum length are eligible