Skip to main content

New answers tagged

0 votes

Is there an equivalent of caniuse for commands on posix systems?

There is no such resource currently. I seriously wish there was, because it would make my job much simpler. Package availability is solved (see https://repology.org/ for the currently best resource ...
Austin Hemmelgarn's user avatar
1 vote

Is there an equivalent of caniuse for commands on posix systems?

Almost no command will be present by default on all flavors with no package installation. You can consider the mandatory utilities section of POSIX standard, but while many of them are present on all ...
Ángel's user avatar
  • 3,584
0 votes

ed(1) adds ^M to every line of my file

Actually, I just discovered that the traditional SunOS "ed" will add carriage returns (^M) to all lines if you edit a file that's missing a newline after the last line. Probably some sort ...
Gordon Ross's user avatar
-2 votes

Make sure that the "cp" command is executed properly

//set $return and $output to null - exec will change these values $output = null; $retval = null; //execute command (you need to know the expected return values) exec('cp -p '.$source.'* '.$...
Jonny O'Gorman's user avatar
3 votes

Is there an equivalent of caniuse for commands on posix systems?

There are a few tools or sites which can be used to find out which version of a project is available in various distributions (including non-Linux systems); see Is there a tool/website to compare ...
Stephen Kitt's user avatar
-1 votes

How to convert multiple columns to rows in shell (unpivoting)

Using Miller, given $ mlr --tsv cat file.tsv OTUId AC0184 AC0250 AC0257 AC0258 AC0262 AC0263 AC0289 AC0293 OTU549024624 51659 0 0 0 0 0 0 0 ...
steeldriver's user avatar
  • 81.9k
1 vote

Get a list of all user's commands from a non-interactive shell

Turns out, I was quite close to the solution. I was confusing login shells and interactive shells. Different things. Instead of $SHELL --login, all I needed to do was $SHELL -i. The following will ...
zoickx's user avatar
  • 51
0 votes

Linux Shell Script replace last shown lines at the screen, not write it under the last once

If you can programmatically determine where you should start, you could echo out ANSI CTRL SEQUENCES For example you could echo the number of backspaces per line and echo up after each line. Or ...
Mike Steele's user avatar
1 vote
Accepted

join a specific number of files/devices in linear mode together in a linux system

You can use a for loop to iterate from zero to 32, and store the device names in an array. # you don't show the file, there are programmatic ways to acquire this number n=33 devices=() for ((i = 0; i ...
glenn jackman's user avatar
5 votes
Accepted

Joining 'fish shell' arguments into a single string with spaces

You're looking for string join ' ' $argv -- docs
glenn jackman's user avatar
0 votes
Accepted

Play sound after command and also pipe output

After reading the answers, I realized that I could simple do: (echo test; print \\a > /dev/tty ) | less The problem with print was that the sound was done through the console, so a redirect solves ...
Luis's user avatar
  • 101
0 votes

Delete 2-line paragraphs, keep 3-line paragraphs, maintain newline between all

Using any awk with a blank line at the end of the output: $ awk -v RS= -F'\n' -v ORS='\n\n' 'NF != 2' file aaa aaaaaa bb bbb cc cccc ccccc cccc fff ff ggg gggg gggg hhh hhh hh hhhh Using any awk ...
Ed Morton's user avatar
  • 32.4k
1 vote

Delete 2-line paragraphs, keep 3-line paragraphs, maintain newline between all

With GNU awk: awk 'BEGIN{FS=RS; RS=""} NF==3{print; print ""}' file Output: aaa aaaaaa bb bbb cc cccc ccccc cccc fff ff ggg gggg gggg hhh hhh hh hhhh Output contains one ...
Cyrus's user avatar
  • 12.4k
-1 votes
Accepted

Delete 2-line paragraphs, keep 3-line paragraphs, maintain newline between all

You can use perl for this (along with several other possibilities) perl -n -00 -e 'chomp; print "$_\n\n" unless y/\n// == 1' datafile Or expanded out somewhat, perl -n -00 -e ' # -n -00 ...
Chris Davies's user avatar
0 votes

Keyboard buffer management

While "sleeping", we can still use the keyboard and anything put on the buffer will be delivered to the input of ipython upon returning from the sleep function. That's not really a feature ...
Marcus Müller's user avatar
2 votes
Accepted

Use fallocate with numbers from text file

If you're trying to loop over a sequence of whitespace separated numbers in a single line of list.txt then one way to do so in the bash shell would be to read them into an indexed array: read -a ...
steeldriver's user avatar
  • 81.9k
1 vote

Bourne Shell EOL characters not working in shell handler

It turns out the issue wasn't actually the command or line terminators it was the way stream reader was handling the response. This is how I was handling the response var stream = ShellTcpClient....
DotNetRussell's user avatar
0 votes

Shell option to display full path of commands as they are executed

strace -f (with options to hone in on just the exec calls) is the best common option, since shell options are meaningless once the spawns are from inside non-shell subprocesses. No normal setting on ...
Alex North-Keys's user avatar
0 votes

Source additional files on login (~/.bash_profile? ~/.bashrc? /etc/profile? /etc/bashrc?)

Home directories are commonly mounted across hosts, but I see that you're putting these host-specific things in /etc, not user homes, i.e. don't use that ~/.bash_rc. You're in luck though - I was ...
Alex North-Keys's user avatar
0 votes

"Command not found" when using ssh and non absolute commands

If you source your current profile settings. E.g. .bashrc or .zshrc, you'll have access to the same $PATH as you do when you login to the server the normal way. I.e. ssh user@server -t 'source ~/....
Pylinux's user avatar
  • 101
10 votes
Accepted

Which interpreter for "Unicode text, UTF-8 text executable"

Your command attempts to run a command called "/path/to/the/executable" - including the double quotes as part of the name: sh -c '\"/path/to/the/executable\" --options' This is ...
Chris Davies's user avatar
3 votes
Accepted

Taking only a four-digit number as user input

Most shells have builtin support for glob pattern matching, few have builtin support for regular expression pattern matching. With standard sh syntax, using glob pattern matching via the case ...
Stéphane Chazelas's user avatar
1 vote
Accepted

Shell/bash: Can I create a file descriptor to an existing file without emptying the file?

You have several options, but those have to be >> file instead of > file in order to not "clobber" that file. For exemple, if you need to redirect STDOUT and STDERR inside your ...
Olivier Dulac's user avatar
1 vote

Play sound after command and also pipe output

What about something like this: echo test | (sleep 1; echo done) & speaker-test -t sine -f 1000 -l 1 This way your command (which is in the parenthesis, just for testing I put there a sleep to ...
Light Darkmatter's user avatar
1 vote

Play sound after command and also pipe output

It seems that the overall goal is not to use the temporary file? That's going to be nearly impossible not to involve a file. If you want to avoid /tmp/tmp.txt you can use a FIFO. mkfifo myfifo (echo ...
JayCravens's user avatar
1 vote

How do I update the contents of a script including comments (django/settings.py) using echo, printf or grep

Your approach would also work, but you need a space between the command, printf, and its arguments (the quoted string you want to print). So while this fails: $ printf'Hello world\n' bash: ...
terdon's user avatar
  • 245k
2 votes
Accepted

How do I update the contents of a script including comments (django/settings.py) using echo, printf or grep

Probably, a "here document" is what suits you need best; e.g., cat <<'END' >app/hello_django/settings.py ''' ... ''' import os ... END Single quote END to protect the doc from any ...
GammaZoid's user avatar
  • 149
1 vote
Accepted

Command not found on shell opening

One trick to find out which source file a given command comes from is to modify PS4 to include the source file name and line in the xtrace output. (See here and here.) E.g. run the shell with ...
ilkkachu's user avatar
  • 141k
4 votes

variable with hyphen in bash script

There's no need for sudo or bash here. postgresql comes with a standalone dropdb executable to remove databases, and more advanced shells like zsh can switch users and do stuff by themselves: #! /bin/...
Stéphane Chazelas's user avatar
5 votes
Accepted

variable with hyphen in bash script

The complexity here is that Postgres requires the database name to be in double quotes. You're also calling an extra layer of shell. Try this instead: db1="community-service-data" db2="...
Chris Davies's user avatar
0 votes

find with du -sch and very many files

I would solve it in TXR Lisp like this. Say that the directories we want to find are characterized by having subdirectories called alpha, beta and gamma: (let* ((dirs (glob* "**/{alpha,beta,gamma}...
Kaz's user avatar
  • 8,585
0 votes

Command not found on shell opening

In the verbose output, there is a line n test -z '' This is the probable reason for the error message. You apparently searched all the standard bash startup files and found nothing. The next step ...
Ljm Dullaart's user avatar
  • 4,863
-1 votes

running script with ". " and with "source "

What is the difference between '.' and 'source' in shells? For bash, . and source behave the same, but their behaviour is affected by whether they are run in POSIX mode or not¹. POSIX ...
n0099's user avatar
  • 151
0 votes

view a bunch of text files in the terminal

Just found a suitable answer https://unix.stackexchange.com/a/513132/188451 head -10000 *.txt That does a nice job printing the file names. Does not leave any space after and the files must not be ...
cardamom's user avatar
  • 602
5 votes
Accepted

find with du -sch and very many files

Your quoting makes no sense, the output of find doesn't get interpreted by a shell; neither does using \n as separator; you should instead always use \0 zero byte as separator and use xargs with -0; ...
Marcus Müller's user avatar
4 votes
Accepted

How to check if part of a symlink goes outside a directory in posix shell

This is not an easy task because the basic tools you have to work with do either too little or too much. Symbolic link resolution inside the kernel can only tell you the ultimate location of a chain ...
Gilles 'SO- stop being evil''s user avatar
0 votes
Accepted

FreeBSD Reverse Shell Command Issue: Ambiguous Output Redirect Error

You are confusing terminologies but more importantly: binaries. You state in the comment that you understand the difference between the shells. But the important part is to understand that there are ...
Claus Andersen's user avatar
3 votes

Running a cronjob that requires setting of several environment variables in particular directory

cron uses a shell to interpret the command line given in the crontab. By default, it's sh, but by setting the SHELL variable in the crontab like you do here, you can get a different shell. So you can ...
Stéphane Chazelas's user avatar
0 votes

regular single column data to multiple rows

Using GNU awk for multi-char RS and RT: $ awk -v RS='KKK-SNMOdb: NONE\n' -F'\n' -v OFS=',' '{ORS=RT; $1=$1; print}' file KKK-SNMImsi: 444444,KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile,KKK-...
Ed Morton's user avatar
  • 32.4k
0 votes

Answer yes in a bash script

A safer and better way to do is add Host * StrictHostKeyChecking accept-new to ~/.ssh/config file. The newer option accept-new in open-ssh client will accept new keys but will reject if the ...
Shivam Anand's user avatar
0 votes

Scope of Local Variables in Shell Functions

I got curious to know how will the state of var change if we run innerFunc in background (i.e. innerFunc &) and intentionally introduce a delay inside it, so it finishes after outerFunc has ...
pavii's user avatar
  • 1
0 votes

How do I use colors in the MOTD?

For some colored output, working with busybox i can have this working: echo -e "\x1b[1;33m LUG Trieste" > motd cat motd
Angelo Dureghello's user avatar
2 votes

How do quotes work in bash regex regarding reserved characters?

It's safe to put any character except ^ or \ inside a bracket expression to make it literal (i.e. change x to [x]) but never put a \ in front of any character that isn't a metacharacter (e.g. the /s ...
Ed Morton's user avatar
  • 32.4k
0 votes
Accepted

Saving ZSH history across SSH sessions

To save history between sessions, you primarily need to set a few variables for history size in your ~/.zshrc. For example. HISTSIZE=10000 HISTFILE=~/.zshistory SAVEHIST=8000 Avoid using export with ...
okapi's user avatar
  • 757
1 vote

shell sleep until next full minute

Of course, I always think about a potential XYProblem : I believe your real goal is to "do something at the next full minute", and not necessarily via "sleep" ? If so, you could: ...
Olivier Dulac's user avatar
5 votes
Accepted

What is PS1 prompt \[\e]0; vs \[\e]2; , it looks like one is for title name of tab, one is for title name of windows

For reference, the \e] prefix is often called "OSC" in documentation (while \e[ is "CSI"). \e]0; (OSC 0) begins a sequence that sets both the terminal's window title and icon ...
u1686_grawity's user avatar
4 votes

shell sleep until next full minute

In the ksh93 shell: sleep '## next minute' Would sleep until the next minute. In ksh93, sleep is builtin and accepts a variety of absolute and relative date specifications as arguments (in addition ...
Stéphane Chazelas's user avatar
0 votes

shell sleep until next full minute

Combining and following up on the existing answers, if you need better accuracy, take into account subseconds as well: sleep $((60 - $(date +%-S.%N)))
daroczig's user avatar
  • 101
0 votes

SSH shows double shell prompt after entering a command

It seems that terminals on Windows don't understand control sequences when TERM is set to xterm*. Try : export TERM=cygwin Another option is to install Git-bash(https://www.git-scm.com/downloads) and ...
Philippe's user avatar
  • 1,475

Top 50 recent answers are included