Tag Info

New answers tagged

1

Do you mean something like this? whiptail --msgbox hello $(stty -a | tr \; \\012 | egrep 'rows|columns' | cut '-d ' -f3)


2

I think your executable file just prints a to the screen. When you write $COMMAND, file executed and the output tried to be executed again.Because it cannot execute a command, it gives an error. You can use just simply $COMMAND or echo `$COMMAND`


1

If you want aliases to be expanded after xargs, you can do: alias xargs='xargs ' However note that only the first word after xargs is subject to alias expansion and that can have unexpected effects if you have aliases for standard commands. $ alias xargs='xargs ' a='echo test' $ set -x $ echo x | xargs a + echo x + xargs echo test test x $ echo x | xargs ...


1

I run FBSD myself. There was a post about this problem elsewhere too. I found that starting the script with the following greatly improves cross OS compatibility: #!/usr/bin/env bash


0

So this is your script: #!/bin/sh if [ ! -d "/opt/ftp/$PAM_USER" ]; then /usr/bin/env mkdir /opt/ftp/$PAM_USER /usr/bin/env chown ftp:ftp /opt/ftp/$PAM_USER fi Try your script with this: #!/bin/sh if [ ! -d "/opt/ftp/${PAM_USER}" ]; then /usr/bin/env mkdir /opt/ftp/${PAM_USER} /usr/bin/env chown ftp:ftp /opt/ftp/${PAM_USER} fi PAM_USER is a ...


3

It can be done, you need process substitution. Redirect the streams into a subprocess that calls tee and redirects the rest into the overwritten file. exec &> >(tee -a backup.log > overwritten.log) Note that this will overwrite the file only once in entire script, because the stream remains open until the script exits or another redirect is ...


2

If the command accepts multiple files as arguments (rather than as the contents read through the pipe), simple command substitution should work: [script/binary/alias] $(find . -name '*') Alternatively, if the command only accepts one file at a time, a for loop should do the trick: for file in $(find . -name '*'); do [script/binary/alias] $file; done In ...


1

These strange escape sequences are color-changing commands. The completion code runs the following command to list available commands: git help -a|egrep '^ [a-zA-Z0-9]' The output of git help -a looks like this: add grep remote add--interactive hash-object remote-ext am ...


0

There isn't really any such thing as a guaranteed set of directories to include in PATH. You'll find /bin but everything else is just probable or possible. Users on my systems will have something like $HOME/bin:/usr/local/bin:/bin:/usr/bin. Root users would have /usr/local/sbin:/sbin:/usr/sbin in there too. If your file might be in one of a number of places ...


4

If you want to split the output into multiple files, each limited to 1000 lines, then use split. If you just want to "truncate the output that goes to another file to a maximum (for example: 1000 lines)," then use head: cmd | head -n1000 >output_file The -n option tells head to limit the number of lines of output. Alternatively, to limit the output ...


4

(this is not really an answer, more of a comment) You have to be a bit careful about the a && b || c shortcuts: if a returns success, then b is executed if b subsequently returns an exit status, then c will be executed too. $ [[ -f /etc/passwd ]] && { echo "file exists"; false; } || echo "file does not exist" file exists file does not ...


5

Assuming you want to use A && B || C, then simply call the function directly: tst && echo "success" || echo "failure" If you want to use [[, you'd have to use the exit value: tst if [[ $? -eq 0 ]] then ...


3

variable indirection will be helpful here: for journal in A B all do indirect="${journal}_1999[@]" echo "$journal: ${!indirect}" done outputs A: JF-1999 JFE-1999 RFS-1999 B: JBF-1999 JFI-1999 JMCB-1999 all: JF-1999 JFE-1999 RFS-1999 JBF-1999 JFI-1999 JMCB-1999 An eval-free rewrite. Arrays of arrays is not something bash is natively suited ...


0

I think there is some misunderstood bash' arrays: Arrays Bash provides one-dimensional indexed and associative array variables. Any variable may be used as an indexed array; the declare builtin will explicitly declare an array. There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned ...


4

Welcome to eval hell! Once you start using it, you never get rid of it. for journal in A B all do eval "echo \"\${${journal}_1999[@]}\"" done There might be a much better way to do it, but I never bother with associative or otherwise nested arrays in shell scripts. If you need such data structures, you might be better off with a scripting language that ...


0

The interactive shell loads .bashrc, the script doesn't. If your $PATH is set in .bashrc and you don't export it, the script doesn't inherit your modifications to $PATH. If you call export PATH, the script should see it. Check export -p to see what variables get exported ($PATH should be among them). Also check $BASH_ENV which could potentially override your ...


1

Your script does not preserve quotes. The original line executed by completion is: git --git-dir=.git for-each-ref '--format=%(refname:short)' refs/tags refs/heads refs/remotes by your script you get: bash -c '/usr/bin/git --git-dir=.git for-each-ref --format=%(refname:short) refs/tags refs/heads refs/remotes' Note the missing quotes around: ...


0

The problem is that running the script as nohup sh /path/to/your/script.sh overrides the shebang line interpreter. When called as sh then bash turns off certain features (that is probably similar with other shells) and thus cannot parse process substitution any more. The solution is to make sure that bash is running without restrictions. This can be done by ...


2

If your system supports zsh command, then in bash script you can run zsh -c 'ls -lhS -- **/*(.D)' This probably requires some explanation: zsh: other than bash, more powerful shell with a lot of features -c: take next argument as a command to execute by zsh ls -lhS: according to your question this is the command you want to execute --: takes care of ...


2

If your find supports it, you can use %s in -printf ("File's size in bytes"). If your sort supports nul-delimited input (-z), you can then do: find . -type f -printf "%s %f\0" | sort -nz | tr '\0' '\n'


2

A possibility would be to point melt to a filesystem that shows modified copies of files. FUSE is a generic way to build filesystem driver implemented by an ordinary program and requiring no privileges. There are many FUSE filesystems around, and there's a good chance that one of them can help you. The idea is to provide a mount point where reading a .melt ...


0

As KaP says: strace it. You can start the strace when it hangs by using -p. Can you reproduce the problem if running as different users (each user runs a single copy)? If you are lucky then the program only deadlocks when programs are started at the same time. If that is the case use '--delay' in GNU Parallel to delay starting the next job.


1

The other problem you had was that you also had extra quotes on the mv line. When you are using echo to print a command that will be copied to a shell you need quote everything twice, once for this shell, and once for the second. your echo mv worked fine as long as the filename did not begin with a dash or contain a single quote. The mv only needed quoted ...


1

What is this program doing - do you know what it's using (shared mem, mutexes, maybe files with the same name and every instance is overwriting it, you could check in tmp directory). Tried to strace it? Don't know the scale of your problem but you could use Docker - https://wiki.archlinux.org/index.php/Docker to create lightweight containers or take a look ...


3

You should never install files into home directories with packages. Instead, you can install default configuration files to /etc/skel so that new users created after your package is installed will have these files copied to their newly created home directories. Users that already exist will not get these new files though. Your application can create config ...


0

~, means the users folder which ever username the user has. But I strongly reccomend that you use /tmp instead, there is no reason to use ~.


3

Basic example of sed usage using this as test.txt: one two three two four two five To replace two with foo in that file: sed -i 's/foo/two/g' test.txt What that means: sed is the name of the command, you'll find lots of tutorials (e.g.) and other documentation online, in addition to man sed. -i means edit a file in place. 's/foo/two/g': the s ...


1

Copied from my own answer on unix.SE: If you are on an Ubuntu host, then you should know that in Ubuntu the entries in ~/.ssh/known_hosts are hashed, so SSH completion cannot read them. This is a feature, not a bug. Even by adding HashKnownHosts no to ~/.ssh/config and /etc/ssh/ssh_config I was unable to prevent the host hashing. However, you can read the ...


0

Found it!! It seems that in Ubuntu the entries in ~/.ssh/known_hosts are hashed, so SSH completion cannot read them. This is a feature, not a bug. Even by adding HashKnownHosts no to ~/.ssh/config and /etc/ssh/ssh_config I was unable to prevent the host hashing. However, the hosts that I am interested in are also found in ~/.ssh/config. Here is a script ...


1

The right way to do that is making the script take the directory as a parameter: for directory in foo*/ do ./test.sh "$directory" done The trailing slash in the for loop ensures that it loops over directories and symlinks to directories. Passing the directory to the script ensures that you can move the script and the target directory anywhere without ...


0

I found that the autocomplete was not working because Ubuntu hashes known hosts. You can add Host * HashKnownHosts no To your .ssh/config file but existing hosts won't be un-hashed.


6

In: $(echo " export TEST_A=1 export TEST_B=2 ") being $(...), just one expansion is parsed as a simple command. So that $(...) expansion undergoes the split+glob operator. The output of echo is trimmed of its trailing newline characters and split into several words on IFS characters (newline, space and tab by default): export TEST_A=1 export ...


-2

You just need to treat filename adding an escape caracter \ before the space. filename=$(echo $i|sed 's/ /\\ /g') mv $filename $new_filename


5

The main problem is that you loop over output of ls command. Use glob * instead: #!/bin/sh cd ~/Data for i in *; do echo "$i" filename="$i" date=$(date -n +%Y-%m-%d) new_filename="${date}${filename}" echo mv "${filename}" "${new_filename}" mv -- "${filename}" "${new_filename}" done Additionally I added -- to mv in order to treat ...


1

In bash: $(...) means sub-command substitution (similar to `...`); $((...)) means arithmetic evaluation substitution; ${...} means variable/parameter substitution; The $(( should be seen as an atomic sequence of characters (necessarily terminated by a ))), it is by no mean equivalent to $ ((, $( ( or $ ( (. OBS: without the $ immediately preceding it, a ...


3

The problem is that $( starts command substitution whereas $(( starts arithmetic expansion. $( (5+2) ) is the command (5+2) i.e. the command 5+2 in a subshell. But that isn't a valid command. $((who)) is replaced by the value of the variable who which is probably undefined i.e. 0.


0

If your input lines are the same type, you can do like this: #!/bin/bash LOG="/root/1.txt" echo "Date | Hostname | Threat | DATE+time | Critical/High | Count | --- | External IP | Internal IP | TCP/UDP | Port | External Port | Category | Vulnerability" > 1.csv < $LOG awk '{print $1" "$2" "$3 " | " $4 " | " $5 " | " $6" "$7 " | " $8" "$9" "$10 " | " ...


1

Arrays are defined differently: components=(Persistence Instrument "Accessory Engine") or components=(Persistence Instrument Accessory\ Engine) And accessed differently: for i in "${components[@]}"


6

Associative array in bash (and in other languages) does not preserve the order of elements in declaration. You can add another associative array to keep track the order of declaration: YELLOW=$'\e[93m' declare -A OP=( [Description]="remote to destination" [Source]="/var/www" [Destination]="/foo/bar" ...


0

From man bash: COMP_WORDBREAKS The set of characters that the readline library treats as word separators when per‐ forming word completion. If COMP_WORDBREAKS is unset, it loses its special properties, even if it is subsequently reset. I thought that was interesting, so I did: printf %q\\n "${COMP_WORDBREAKS}" ...


4

Run it through your shell: sudo bash -c 'source /home/reachus/.bashrc; custom_cmd 80' Alternatively, write a script which sources .bashrc for you, say /usr/local/bin/my: #! /bin/bash source /home/reachus/.bashrc "$@" Then do: sudo my custom_cmd 80


0

There are two ways to interpret the question: you want the completion while you are typing the names before the closing } (in effect performing completion of files in another directory); or, you want the completion to expand and substitute the (valid) names after the closing }. { } expansion expands all the options, unlike globbing which expands existing ...


0

Braces (which, by definition, are "curly") in this context refer to a list of fragments of text, separated by commas. While it's most often used for file names, it gets expanded before file name expansions are handled. Therefore, there is no definitive expansion capability, because bash cannot know if you're actually typing a file name or not.


2

Using paste paste -d'\n' - - /dev/null <file


4

Yes, you can do it in bash but I have no idea why you would want to. Here's a pure bash solution: $ while read -r mon day time host threat date time crit count sugg out exip \ in inip tcp port export cat vuln; do printf "%s | " "$mon $day $time" "$host" "$threat" "$date $time" \ "$crit $count $sugg" "$out $exip" ...


1

Hmm... Seems like you could take better advantage of the --format argument here to use --printf instead and just pass the lot over a pipe. Also, your if...fi is a compound command - it can take a redirect which all contained commands will inherit, so maybe you don't need to nest the heredoc at all. if [ "$diffLines" = 1 ] then stat --printf "Last ...


0

The other method would be herestrings: mail_content="Last Change: $dateLastChanged This is an automated warning of stale data for the UNC-G Blackboard Snapshot process." mailx -r "Systems and Operations <sysadmin@[redacted].edu>" -s "Warning Stale BB Data" jadavis6@[redacted].edu <<<"$mail_content"


1

sed n\;G <infile ... is all you need ... For example: seq 6 | sed n\;G OUTPUT: 1 2 3 4 5 6 ...(and a blank follows the 6 as well)...or... seq 5 | sed n\;G OUTPUT: 1 2 3 4 5 (and no blank follows the 5) If a blank should always be omitted in a last line case: sed 'n;$!G' <infile


1

You should use the serial device much like a normal file. The only difference is that it needs some ioctl()s to do the speed and control line setup. So don't use os.system("echo ... but f = open('/dev/ttyUSB3', 'rw') and then f.write() and f.read(). In theory you could use ioctl() to set the speed and so on, but at that stage it's simply easier to use ...


0

The general approach is to read the file names from the archive (unless they are always the same) and then have tar extract only one file at a time. GNU tar has the option --to-stdout which prevents it from writing a file. Without that you would need a FIFO for each file name. > tar -tf subdir.tar.gz R1.fastq R1.fastq tar -xf subdir.tar.gz --to-stdout ...



Top 50 recent answers are included