10 votes

What are the ideas behind the absence of quote removal and escaping in variable expansion?

This behavior makes passing arbitrary arguments using one variable very difficult [...] Perhaps. But having the results of expansions go through all the usual command line processing would make it ...
  • 121k
2 votes

PROMPT_COMMAND output in shell script using piping LINUX

$PROMPT_COMMAND is specific to the bash shell. It's a special variable that is meant to contain bash code that is evaluated before each prompt is displayed, so it's only relevant in interactive shells ...
2 votes

How to change the modification date (The Metadata) of multiple files?

Update: If I am wrong with this answer please let me now. I'm not sure if file system's modification date metadata is equivalent to exitf modification date metadata. I tested with exiftool and the ...
2 votes

What are the ideas behind the absence of quote removal and escaping in variable expansion?

Because quote removal works only on quotes that are in the shell syntax, it is, in princple a compilable feature. So that is to say, there doesn't actually have to be any run-time quote removal going ...
  • 6,820
2 votes

find the partition and block device for a filesystem *without* string manipulation

If you create a udev rule, you can pass environment variables from it, to your script with arguments. Where %n is the kernel number of the device (i.e %n from /dev/sda1 gives you 1). And where %P is ...
2 votes

find the partition and block device for a filesystem *without* string manipulation

We could search all paths under /sys/block/ to find one that has our partition. Instead of searching all paths, you could just read the symlink... $ readlink /sys/class/block/sdb17 […]/block/sdb/...
  • 43.1k
1 vote

the output between zsh and bash

A variable that doesn't exist in the environment doesn't have any value, so there is nothing there to print. It isn't that variables magically get the value 0, if they are not defined, they are not ...
  • 221k
1 vote
Accepted

How to make a script to rename images and videos with the date of modification?

Here's a script that I think would do what you ask. I first define a function that takes an extension and a type (either "IMG" or "VID"), uses find to get all the regular files ...
  • 7,582
1 vote

Sed replace the middle string

With zsh, assuming list doesn't contain $, ` nor \ characters: $ cat list 22<>22 3<>33 134423<>4 $ cat data test dev too $ () {print -rC1 -- ${(e)${(f)"$(<list)"}//'<&...
1 vote

Sed replace the middle string

change <> to one character | delimiter: $ sed -s 's/<>/|/g' asdf1 > asdf2 $ cat asdf2 22|22 3|33 134423|4 combine 2 files into one file, using same one character | delimiter: $ paste -...
  • 169
1 vote
Accepted

Sed replace the middle string

You can assign to an array the list of strings that will replace to <>. In a file called list.txt you should have: test dev too And in a file called data.txt you should have: 22<>22 3<&...
1 vote

add a new line after a specific string in a file?

I'm going to assume that echo is just a typo because unless there's something specific with your environment, that same command just gives the output sed '/Random/a\ newly added line' info.txt If you ...
  • 9,841
1 vote

Save a variable to environment till it is not erased

"If vm reboots, will that value be saved" -- No. Write it to a file instead. id_file=$HOME/.local/data/cli-command.id # delete the old one cli-command-delete "$(<"$id_file"...
1 vote

Collapse multi-line records into single CSV lines containing the "value" parts only

It seems you want to collapse multi-line records into single CSV lines, only print the values of the record attributes Name, Admin and Oper and print "explicit" empty fields where one of ...
  • 19.3k
1 vote

Searching filename for certain string and saving it to a variable in a shell script

Assuming the values are integers, regular expression matching would be a concise way to extract the values. This is bash: file='x=1,y=15,z=63.txt' if [[ $file =~ "x="([0-9]+)",y="(...
1 vote

Shorthand to declare boolean

You're asking for something similar to this: HOME_IS_BASE_DIR=$("home" == "${BASE_DIRECTORY}") USERS_IS_BASE_DIR=$("Users" == "${BASE_DIRECTORY}") You can make ...
  • 175
1 vote

Bash script; optimization of processing speed

My quick takes: Avoid subshells. Remember that { } (no subshell) can often/sometimes be used instead of ( ) (subshell) Use shell built-in functions in favour of external commands. e.g. get the ...
  • 175

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