Skip to main content

New answers tagged

0 votes

How to debug csh scripts?

I tried this and seems I can see debug output in the terminal. set echo For scripts you can call with csh -x <scriptname>
k_vishwanath's user avatar
0 votes

GNU parted resizepart in script

Running Parted in script mode --script did not work for the OP: root@195-xxx-xxx-xxx:/proc# parted --script /dev/sda unit B resizepart 2 1166016512B Warning: Shrinking a partition can cause data loss,...
FlexMcMurphy's user avatar
0 votes

How to use parted in script mode?

In this case the OP was trying to shrink a partition. When Parted is running in script-mode -s like this: parted -s /dev/sdb unit MiB resizepart 1 307199 ... it will not shrink a partition by design ...
FlexMcMurphy's user avatar
0 votes

Regarding Nested loops

Perhaps #!/usr/bin/env bash declare -a arr1=("F" "S" "M" ) declare -a arr2=("O" "F" "C" ) declare -a arr3=(2.0 3.5 4.5 4.0 3.0 3.0 3.0 ...
glenn jackman's user avatar
0 votes

Regarding Nested loops

I still don't understand exactly what you want to achieve, but the following code tries all the combinations of the first two arrays while there is a value in the third array. #! /bin/bash declare -a ...
choroba's user avatar
  • 47.7k
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
0 votes

How to cause an error 77 EBADFD in Linux

Exit code 77 is typically used by test programs to indicate that the test hasn't run. It could be reported as "skipped" by the test harness. This convention was introduced by GNU Automake ...
Paolo Bonzini's user avatar
0 votes
Accepted

How can I get stderr from mbuffer written to log file when using tee?

Answer From the mbuffer manpage: -l <file> Log messages to file instead of standard error output. and -q Quiet - do not display the status on the standard error output. Combining ...
Vilinkameni's user avatar
  • 1,225
-1 votes
Accepted

runuser: execute commands without use of quotation marks?

This fulfills ALL requirements: Allows sandboxed code to be read as it is. Allows complex quotation in runuser. Execution is done by a different user without setuid bit in an isolated environment (...
GrabbenD's user avatar
  • 144
0 votes

Changing a file's modified date based on date in file name

For everybody who wants to preserve the modification time and change only the date, use this code: #!/bin/bash for name in IMG-[0-9]*.jpg; do date=$(stat -c '%y' $name) newdate="${name:4:...
Freeze's user avatar
  • 1
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
Accepted

Using awk, append a value in last field in csv file based upon value in specific field

Here's one awk approach: ## This function takes as input an awk array whose indices are ## IDs and whose value is the number of times that ID has been seen. ## It returns the ID with the maximum value....
terdon's user avatar
  • 245k
1 vote

Using awk, append a value in last field in csv file based upon value in specific field

This sounds too complicated to do it reliably and quickly in awk. You'll want to treat your "row groups" individually. A program in a mainstream programming language with a reasonable CSV ...
Marcus Müller's user avatar
0 votes

script / command to get IPs from list of hostnames and combine into a single file

Here is a script if still required :) #!/bin/bash # Function to perform nslookup for an IP address perform_nslookup() { result=$(nslookup $1) echo -e "NSLookup for $1:\n$result" } #...
Tiborcz Kiss's user avatar
2 votes
Accepted

Can I make a script that Reboots and continues after?

@larsks already provided the definitive answer here as a comment - but just for the lafs.... #!/bin/bash STATE="/tmp/$( basename "$BASHSOURCE" )" REPEAT=10 function install() { ...
symcbean's user avatar
  • 5,839
0 votes

Can I make a script that Reboots and continues after?

First at all, you need some file to remember the reboot times: $ echo 1 > xx $ read x 9 ## key in by keyboard $ echo ${x} 9 ## Check the value of {x} $ read x < xx ## Read the ...
James's user avatar
  • 49
1 vote

Can I make a script that Reboots and continues after?

I don't think it'll work for your particular case but the approach can be used in similar situations and it's too long for a comment On Linux it could be achieved by enabling hibernation and doing ...
Arkadiusz Drabczyk's user avatar
2 votes

Remove duplicates in file (without sorting!) leaving the _last_ of the occurences

You could prevent kile from polluting your history by invoking it as unset HISTFILE;HISTSIZE=0 kile. Also, see my AskUbuntu answer: https://askubuntu.com/questions/80371/bash-history-handling-with-...
waltinator's user avatar
  • 5,255
2 votes

Remove duplicates in file (without sorting!) leaving the _last_ of the occurences

Rather than answer the Question as written, I'm going to offer a suggestion for fixing the underlying issue. First, if you haven't already, file a bug against Kile; it seems like there ought to at ...
Matthew's user avatar
  • 159
0 votes

Piping Backups through Compression and Encryption

--symmetric is misleading: it’s doing symmetric-key encryption (as opposed to public-key encryption). It doesn’t mean that data piped to --symmetric will be decrypted. Instead gpg is adding metadata (...
rumpel's user avatar
  • 374
5 votes
Accepted

How to POSIX-ly ignore "warning: command substitution: ignored null byte in input"?

If the question is how to ignore the warnings or errors that the shell outputs when you try to do something not supported such as here a command substitution with a command that outputs NULs in the ...
Stéphane Chazelas's user avatar
3 votes

How to POSIX-ly ignore "warning: command substitution: ignored null byte in input"?

The error message you are getting is from the shell.  To ignore/suppress it, you need to redirect stderr for the shell.  When you do rpi_model_name=$(cat /sys/firmware/devicetree/base/model 2>/dev/...
G-Man Says 'Reinstate Monica''s user avatar
7 votes

How to POSIX-ly ignore "warning: command substitution: ignored null byte in input"?

Ignoring or explicitly deleting an unknown number of zero bytes without understanding where they come from seems like a bad idea! So, let's actually look at where that comes from and in which cases we ...
Marcus Müller's user avatar
2 votes

How to POSIX-ly ignore "warning: command substitution: ignored null byte in input"?

This worked for me on Raspberry Pi 4 with Debian 12 Bookworm, and it should be a portable solution (adhering to POSIX). We can translate all of the NULL characters with an empty string, effectively ...
Vlastimil Burián's user avatar
0 votes

runuser: execute commands without use of quotation marks?

I would use: /usr/sbin/runuser -l ${dynamicuser} -c The -l makes it inherit what it normally would as that user (the user environment) so $USER and ~ should be interpreted as intended. You might run ...
Mike Steele's user avatar
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
0 votes

Bash script to compress nested directories not traversing correctly

Your script, starting from /start, does cd 0, after which you land in /start/0, then cd 0, after which you land in /start/0/0, then cd 1, after which you land in /start/0/0/1, not /start/0/1, then cd ...
Stéphane Chazelas's user avatar
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
Accepted

Bash script to compress nested directories not traversing correctly

Instead of cd, use the -C option of tar: Something like (untested): #!/bin/bash for i in {0..9} do for j in {0..9} do for k in {0..9} do [ -d $i/$j/$k ] &&...
Kaz's user avatar
  • 8,585
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
0 votes

Script to toggle setxkbmap

This always worked for me. But there is no ctrl_escape toggle unfortunately from what I can see in man xkeyboard-config setxkbmap us,se -option grp:alt_shift_toggle &>/dev/null
vakio's user avatar
  • 101
-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
1 vote

xsel like a clipboard manager: keep clipboard content for future use

Finally, I've found the solution. xsd is based on xclipd and fixes this issue in it. I run xsd in startup script and both clipboard and file copy using "Ctrl-C-Ctrl-V" work fine.
Anton Vakulenko's user avatar
8 votes
Accepted

Why does redirecting stderr interfere with bash's handling of $COLUMNS and the `checkwinsize` option?

In your scenario, Bash retrieves the “window” size from the terminal associated with its standard error, if any. Redirecting standard error means it can’t do this, so COLUMNS remains unchanged even if ...
Stephen Kitt's user avatar
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
1 vote

xsel like a clipboard manager: keep clipboard content for future use

If you absolutely want to do this manually, this will provide a constant backup of your most recent copy. #!/bin/bash history_file="clipboard_history.txt" last_item="" >"$...
JayCravens's user avatar
0 votes

xsel like a clipboard manager: keep clipboard content for future use

If you just want your clipboard to work, you should run a clipboard manager. The lightest one I know of is xclipd. Try this: Clone the xclipd repository and cd to the folder. Run make. Now run ./...
wobtax's user avatar
  • 318
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
1 vote
Accepted

Remove duplicates in file (without sorting!) leaving the _last_ of the occurences

awk '{ delete line[lnum[$0]]; line[NR] = $0; lnum[$0] = NR } END { for (n = 1; n <= NR; n++) { if (n in line) print line[n] } }' We maintain two associative arrays. line[i] gives us the ...
Kaz's user avatar
  • 8,585
6 votes

Remove duplicates in file (without sorting!) leaving the _last_ of the occurences

You can reverse the file, process it, and reverse it back. Most systems have either tail -r or GNU tac (or its busybox or toybox clone) for that: ( umask 077 # make sure the new ~/.bash_history ...
Stephen Kitt's user avatar
0 votes

Is there a function in shell script equivalent a var_dump(PHP)

simple_var="SIMPLE VAR" declare -A languages=([en]=ENGLISH [hu]=HUNGARIAN) var_dump() { for var_name in "$@"; do set | grep "^$var_name=" done } var_dump ...
Peter Toth'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" ...
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

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
5 votes
Accepted

Grep return No such File, after comand substituion

Nothing weird there, just the command substitution working. When you tested the command $(grep -R -I --exclude-dir=addons "^[^#]*print(" ) the shell first performed the command substitution ...
telcoM's user avatar
  • 101k
3 votes

Is it possible to translate bash to another human language like Arabic?

Sure, you can just go and translate all of bash's commands; it's free and open source, exactly because you should be able to do whatever you like with it. It certainly would be a lot of work – the ...
Marcus Müller's user avatar

Top 50 recent answers are included