All Questions
71 questions
0
votes
2
answers
97
views
How to redirect output from a program that waits for input
Following this post I created my own version of the script, with the difference that user and password are forwarded from the environment variables:
#!/bin/zsh
pamtester login $user authenticate <&...
3
votes
2
answers
445
views
"history" command ordered by most common
Can I get the output of history sorted in order of most-used?
I know how to do it in a programming language, but not from the shell. In my case I'm on macOS with zsh.
I know I could use uniq and sort ...
1
vote
2
answers
119
views
Start interactive function definition from shell-script
Using zsh or bash, I want to run a script that may prompt the user for multiple commands and store them as a function, however I'm finding that eval "function $FNCNAME() {" or echo "...
1
vote
1
answer
214
views
Log a list of files and open them with VSCode CLI
I'm trying to create a macro on my shell.
The operation I'm trying to automate is this one:
Find all the files containing TEXT_TO_SEARCH, and open them with VSCODE
I can do this with a one-liner
$ ...
2
votes
1
answer
465
views
if var='value' then in Zsh: Is it really a valid syntax without semicolon?
The following code works on Zsh 5.8 that I tried, despite the missing semicolon. But is it really a valid Zsh syntax?
#!/bin/zsh
if var='value' then
echo 'then'
fi
Without an assignation that ...
0
votes
0
answers
49
views
Compress list of files as their shortest exclusive glob
How can I convert a list of files to the minimum-length glob that expands to those files and no others?
E.g. in a directory
root
├── one
└── two
Then the list root/one:root/two can be converted to ...
0
votes
1
answer
116
views
Where should I put my personal shell script in terms of safety?
I am learning sh to make some customized function. I am looking for a safety location for the personal script, since I check from stack exchange, some say that put personal script under ~/bin may ...
0
votes
1
answer
907
views
Shell script: How to prepend env variable with prefix only if environment variable is defined?
Given command that requires flag --flag. We want to insert this flag only when the value of the flag is provided as environment variable VALUE.
I tried the following:
echo "command ${X+--flag ${...
5
votes
1
answer
2k
views
zsh: pass variable by reference, and modify its value (like bash's local -n namerefs)?
Is it possible to pass a variable to a zsh function, and modify its value without using eval? I came across a bash way to do that: local -n: https://stackoverflow.com/a/50281697
0
votes
2
answers
87
views
What's a clean way to run a specific command C for each line L of a given file F and then move every L where C(L) ran unsuccesfully?
Say that
https://example.nosuchtld
https://example.net
https://example.org
https://example.willfail
is the content of urls.txt. I want to run <command> <url> for every URL/line of urls....
0
votes
0
answers
36
views
Linux bash not working properlly [duplicate]
I am trying to run the following script on a OpenSuse machine:
OUR_REPO=$(git branch | grep "*" | awk '{print $2}')
THE_REPO_THAT_OURS_IS_BASED_ON="origin/$OUR_REPO"
GIT_COMMIT=$(...
1
vote
2
answers
171
views
Echo contents of for loop automatically
I often use a for loop to i.e. convert a bunch of file formats. In some cases, where text transformations or variables occur, it would be nice to check if the substitutions were performed correctly.
...
1
vote
2
answers
2k
views
How do you execute ls -la when encoded as hex?
There used to be a really bad joke from the internet where you would copy something starting with \x0B\x2E... (just an example) and when you execute this command the terminal would interpret it as ...
0
votes
1
answer
1k
views
What does $^@ (dollar caret at) mean in a shell script?
I found references for parameter expansion, but none of them explain what $^@ does. From context, I think it's used to expand e.g. ~/$^@ into ~/$1 ~/$2 ..., but I'm not sure, and I can't find any ...
4
votes
1
answer
2k
views
Understanding $@ in bash or zsh
myFun1 and myFun2 below don't produce the same output. Why?
#!/bin/bash
myFun1() {
local item
IFS=:
for item in "${@}"; do
echo "->${item}<-"
done
}
myFun2() {
...