shell

Replace last nonblank line with a command output

Replace last nonblank line with a command output I have a .env file like PARAM1=val PARAM2=val I want to replace the last noblank line with another file content So far I have something like below: { (sed -e :a -e ‘/^n*$/{$d;N;ba’ -e ‘}’ local.env | sed ‘$d’ local.env && printf "CONFIG=%s" "$(cat config.json | jq …

Total answers: 2

How to redirect a command for a specific application

How to redirect a command for a specific application For example, the feh program can delete the currently viewed image, presumably using the rm command at some point. Let’s say that instead of deleting the file, we want to run a trash script, say trash.sh. Is there anyway of running feh but tricking it into …

Total answers: 1

What does mean `^(*.c|*.md)`

What does mean `^(*.c|*.md)` I am sorry if it is a potential obvious question, but I have no idea what ^() means in ls ^(*.c|*.md) On zsh, this argument expands to everything but *.c and *.md files. What is ^? What does mean the parenthesis () in this context The command ^(*.c||*.md) also works… Should …

Total answers: 1

Copy file from Server A to Server B

Copy file from Server A to Server B I have requirement to copy files from Server A to Server B And then move the copied files Server A to Archive folder I have written the script, but it takes the directory name differently. Copying file from Server A to Server B is working, but moving …

Total answers: 2

Pass result of find command as another command's multiple options

Pass result of find command as another command's multiple options I have a CLI tool that can take an option with multiple values – The syntax is like this: CLI -I path/to/file1 -I path/to/file2 … How can I pass the result of the find command to this CLI? For reference If it’s positional multiple arguments: …

Total answers: 3

zsh -z test meaning of "+x"

zsh -z test meaning of "+x" I am new to zsh and have been a bash user for years. In an example zsh script I see a test: if [ ! -z ${ZSH_MOTD_CUSTOM+x} ]; then In bash I would expect: if [ ! -z "$ZSH_MOTD_CUSTOM" ]; then I don’t understand the meaning of +x in …

Total answers: 3

Why pipe keep sudo and redirection not?

Why pipe keep sudo and redirection not? Pipe (|) and redirections (<, <<, >, >>) both using standard streams (stdin, stdout, stderr), but although only pipe can keep sudo privileges, why? Works: sudo echo "hello" | tee /root/test Doesn’t work: sudo echo "hello" > /root/test Asked By: linuxer || Source Pipe (|) and redirections (<, …

Total answers: 2

Converting a tcsh alias into zsh

Converting a tcsh alias into zsh I had a tcsh alias as follows: alias cdd ‘cd `dirname !*`’ I use this to change the directory to the one containing a certain file. For instance, cdd /Users/myself/Document/Folder/File.pdf would change the directory to /Users/myself/Document/Folder/. How could I "convert it" to the zsh shell? Asked By: leparc || …

Total answers: 1

Does `return 0` equal `true` (in sourced script to shell's environment)?

Does `return 0` equal `true` (in sourced script to shell's environment)? I am working on a highly portable script that users shall source to their shells, forcing me to use POSIX scripting. There are many useful functions in the script, one of them is special though, as it returns true or false status to the …

Total answers: 3

sed: -e expression #1, char 101: unterminated `s' command

sed: -e expression #1, char 101: unterminated `s' command can someone suggest me what is going wrong here – sed -i "s|##CONNECTION_DETAILS##|${CONNECTION_DETAILS}|g" dep.yaml. The value of CONNECTION_DETAILS is in encoded form: CSAgewogICAgICAgICJjb25uZWN0aW9uX25hbWVfMSI6ICJPRlNBQV9BTkFMWVRJQ1NfUFVCIiwKICAgICAgICAiZGF0YWJhc2VfbmFtZV8xIjogIk9GU0FBX0FOQUxZVElDU19QVUIiLAogICAgICAgICJiaV9TZXJ2aWNlc18xIjpbImR2IiwicnBkIiwiYmlwdWJsaXNoZXIiXQogICAgICB9Cg== for: { "connection_name_1": "OFSAA_ANALYTICS_PUB", "database_name_1": "OFSAA_ANALYTICS_PUB", "bi_Services_1":["dv","rpd","bipublisher"] } Asked By: Meenal || Source Your CONNECTION_DETAILS variable contains LF (n) characters. So, sed don’t …

Total answers: 3

Is it now safe to parse the output of GNU ls?

Is it now safe to parse the output of GNU ls? The accepted wisdom for the past few decades has been that it is never a good idea to parse the output of ls ([1],[2]). For example, if I want to save a file’s modification date along with its name into a shell variable, this …

Total answers: 3

How to find files created one hours before?

How to find files created one hours before? I have the folder, the files will comning hourly daily in here. After that, i want to copy only files, which created date one hours before to other folder. For example: Currently datetime is 9:20:00AM, I want to copy files with create date from 8:00:00AM to 8:59:59AM …

Total answers: 2

How do you find the path from where a cli is called from?

How do you find the path from where a cli is called from? Let’s say I’m building a CLI app. Let’s say it’s written in Python. For simplicity’s sake, let’s say this app echoes the given dir or file canonical path. The user calls myApp .. How can my app know where it is being …

Total answers: 2

What's the difference between "-dm" and "-Dm" in GNU Screen?

What's the difference between "-dm" and "-Dm" in GNU Screen? The GNU Screen manual says: `-d -m’ Start `screen’ in _detached mode. This creates a new session but doesn’t attach to it. This is useful for system startup scripts. `-D -m’ This also starts `screen’ in _detached_ mode, but doesn’t fork a new process. The …

Total answers: 1

Calling vim in subprocess after running cat

Calling vim in subprocess after running cat I am trying to create a bash function vim_run which operates as follows: user pipes command output into vim_run user can edit output user exits vim and the contents of that buffer are now executed via source file This flow is useful for editing a list of files …

Total answers: 1

find -exec bash -c {} +: why only one file of found two?

find -exec bash -c {} +: why only one file of found two? touch 1.txt 2.txt find . -name "[12].txt" -exec sh -c ‘echo "${1}"’ sh {} + -exec echo {} + ./2.txt ./2.txt ./1.txt Why echo within sh -c outputs only one file? Today I thought I understood how find works from Understanding the …

Total answers: 1

How to print a list of .pdf documents without opening them

How to print a list of .pdf documents without opening them I have a list of files in the following format: file1.pdf file2.pdf file3.pdf … how to print them on my printer without opening them I can print a file with the command lp file1.pdf Asked By: Kire || Source If I understood your question …

Total answers: 1

How to make bash not assign a n to a variable?

How to make bash not assign a n to a variable? I have a variable that goes more or less like this: $ echo "$LIST" file1: ok file2: ok file3: file4: file5: ok Then I need to get the list of files that are not ok: $ sed ‘/:s.+$/d’ <<< "$LIST" file3: file4: That works …

Total answers: 3