Tag Info

New answers tagged

0

I ended up using the AttributeMask and AttributeValue settings to achieve the same purpose. An AttributeMask and AttributeValue of 0x2000 (8192) will test whether the file is encrypted.


1

less also recognizes start-of-line anchor ^ and greedy matching operator *. man -P "less '+/^ *'pushd" bash manbb() { man -P "less '+/^ *'${1}" bash } manbb pushd


0

Suppose you want to write count: 1 to a file. For Windows, echo count: 1>file.txt will write count : to the file (without the 1) because the 1 is interpreted to mean stdout. You could use echo count: 1 >file.txt, but then there is an unwanted trailing space. Placing the redirection at the front avoids the problem: >file.txt echo count: 1. Not ...


0

This works: #!/bin/bash results=($(mysql --user root -pwelcome ts -Bse "SELECT type, network_id, subnet_msk FROM remote_subnet;")) cnt=${#results[@]} for (( i=0 ; i<cnt ; i++ )) do echo "Record No. $i: ${results[$i]}" fieldA=${results[0]}; fieldB=${results[1]}; fieldC=${results[2]}; done


0

#! bin/bash query="select * from test;" myarray=$(mysql -h hostname -u user -ppass database << eof $query eof) echo $myarray


2

For such simple examples it does not matter where the redirection happens. It's a choice of coding style here. The Bash manual states: The (...) redirection operators may precede or appear anywhere within a simple command or may follow a command. What is a simple command? A simple command is the kind of command encountered most often. It’s just a ...


1

Why are you installing one item at a time via a script? No need to do this when you can just place all items in one line like this: yum -y install libstdc++.i686 ibibcm.x86_64 librdmacm.x86_64 ibsim.x86_64 ibutils.x86_64 libcxgb3.x86_64 libibmad.x86_64 libipathverbs.x86_64 Now that said, I don’t believe all of the yum -y install directives are running ...


0

If you threw the process into the background, you can just type fg to resume where you left off, otherwise you can disown the program, open screen, reattach the PID using screen, and finally use reptyr to get the process back while in screen $ disown yourprogram # Detach yourprogram from the shell $ screen # Launch screen $ ...


0

If you set the shell variable PROMPT_COMMAND to a command, then that command will be executed every time the shell is about to issue a (primary) prompt.  For example, % ls file1 file2 % PROMPT_COMMAND=date Thu, Nov 20, 2014 1:23:42 PM % ls file1 file2 Thu, Nov 20, 2014 1:23:45 PM % This can be a program, a script, or whatever.


0

Assuming you are not using screen and that the process was stopped using the "SIGTSTP" or "SIGSTOP" signal, you could always try to send the "CONTINUE" signal to the process like this : kill -SIGCONT $PID where $PID is your process id.


0

When you close the terminal, the process is sent SIGHUP, the hangup signal. Unless you are using a utility like screen or nohup, or the program is especially oddly-behaving, SIGHUP will cause the process to gracefully terminate.


2

If you start the process originally using screen you can reattach later: Run screen -D -R Run your command in there. Press Ctrl A then D to disconnect from screen. The process will continue running and you will be returned to the original shell. Then, later, from any terminal: Run screen -D -R You'll be back in the screen shell, where your program will ...


4

I think once you detach your terminal from a process by logging out, you lose the ability to re-attach. Unless you are using a utility like screen to manage your sessions. This may help.... http://unix.stackexchange.com/questions/31824/how-to-attach-terminal-to-detached-process


3

The following tests whether the local timezone has changed since yesterday: [ "$(date -d "yesterday" '+%z')" = "$(date '+%z')" ] The %z format asks date to return the timezone. The above compares the result for today versus the result for yesterday. How to use it The test command can be used to control statement execution: $ [ "$(date -d "yesterday" ...


0

Dopn’t panic! The file /bin/sh is simply a binary file for the shell on the system which is bash. Here is the output of me running /bin/sh -version on my Mac OS X 10.9.5 (Mavericks) install: GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin13) Copyright (C) 2007 Free Software Foundation, Inc. Your removal of it is one thing, but if it was damaged ...


0

Ok, and now for the serious answer ;-) (I discovered this seconds after I had poster my original answer. But I'm still keeping the old answer, just for fun.) I think you could use this: https://powerline.readthedocs.org/en/latest/usage/shell-prompts.html#bash-prompt. Disclaimer: I haven't tested it!


0

Cool question. To my knowledge, this can't be done with Bash alone, as David Postill said. But as he suggested, you could (ab)use the prompt for this purpose. Here's an example using ANSI escape sequences to achieve the effect of a status bar :-) PS1='\[\e[s\e[1;1H\e[41;1m\e[K\e[33;1m\][ *** \t *** ]\[\e[0m\e[u\]\w> ' This one just displays the current ...


1

You can do it with grep cat filename | grep -A1 TWITTER | grep -v TWITTER or, perhaps better, you can do it with awk awk '/TWITTER/{getline; print}' filename


0

I had similar issue but also for not logged-in users. Restart of nscd didn't help, but executing this command did: nscd -i group. That should instruct nscd (caching daemon) to reload the groups file.


0

Find the bus number your device is on (see shekar's answer). Then on the raw /dev/usbmonX, use pipemeter (or pipebench) to measure throughput, or dump it to a file and visualize its growth with speedometer..f.e. for device on bus number 2: # next three commands are equivalent - use any one # pipemeter /dev/usbmon2 > /dev/null # pipemeter < ...


4

First thing: to run a command in the background you type it followed by a single & , the double && is a logical and operator (as well as || is logical or). Running command1 && command2 returns logical true (i.e. return code 0, which means "no error") if both commands return without error. As a much used side effect, command2 is not ...


1

In Bash with the path given in a shell variable (e.g. $DIR) you can always obtain the last (lowest) path component using the basename command and the remaining path up with the dirname command: DIR="/home/user/mail/work/spam" LAST="$( basename "$DIR" )" DIR=""$( dirname "$DIR" )" results in $DIR=/home/user/mail/work and $LAST=spam But why use variables ...


1

To expand on ennuikiller's solution: realpath () { # realpath() -- print absolute path (os.path.realpath) to $1 # note: OSX does not have readlink -f python -c "import os,sys; print(os.path.realpath(os.path.expanduser(sys.argv[1])))" "${1}" return } walkpath () { # walkpath() -- walk down path $1 and ...


0

Depending on what you're trying to achieve, your either need to quote these */*: xs="foo/bar '*/*'" #! xs_cmd="" for x in $xs ; do xs_cmd="$xs_cmd -0 $x " done echo $xs_cmd eval echo $xs_cmd eval "echo $xs_cmd" or use arrays, or both: xs=("foo/bar" "*/*") #! xs_cmd="" for x in "${xs[@]}"; do xs_cmd="$xs_cmd -0 '$x' " #! done echo "$xs_cmd" ...


1

I think this is not as straight forward as one might think. You have to intercept STDOUT, as external programs directly write to that channel. The following is kind of a proof of concept . Be aware, that this will break a lot of things, namely interactive programs like man, less etc. So it's not usable for every-day-use, but to easily format a shell session ...


3

Answering directly to your question title: Yes, there is: The prompt variables are listed in the PARAMETERS USED BY THE SHELL section of man zshparam. The prompt escape sequences are explained in the SIMPLE PROMPT ESCAPES section of man zshmisc. If you don't know in which man page you find the desired information, you can use man zshall.


1

Here are a few online references to resources regarding zsh and prompts: http://zsh.sourceforge.net/Intro/intro_14.html http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html https://wiki.archlinux.org/index.php/zsh#Prompts


1

With zsh a handy shortcut to duplicate the previous word (depending on your zle mode) is EscCtrl _ , that's the default in emacs mode. You can (re)define this yourself. e.g. just Ctrl_ which is good in a vi mode: bindkey "^_" copy-prev-word bindkey "^_" copy-prev-shell-word # respects shell quote/escape With the default bash readline bindings you can ...


0

I always just use tab as so: file name here: test file long name.txt so on command line ren test tab will automagically fill in the full file name with escape chars already there right then hit space so I can begin the new name and again just typing test tab gives me the same file name again with escape characters so it is now User@server:~/$ test\ ...


0

The rename utility is pretty useful in situations like changing case and such. Otherwise I use tab-expansion for one-off edits: mv File Tab File Tab will produce: mv File\ With\ A\ Long\ Name.txt File\ With\ A\ Long\ Name.txt which you can then edit on the command line as you'd like.


1

I usually fall back to tab-completion and readline editing. However, here's a bash rewrite of your python script (requires version 4 I think for the fancy read options) mvInPlace () { local path newpath for path in "$@"; do if [[ ! -f "$path" ]]; then echo "No such file: $path" >&2 continue fi ...


0

The solution I came up with is a simple Python script that relies on the functionality of the readline module. I use it like this: mvInPlace <PATH-TO-MOVE>. The script will now prompt for a new name/path, which is pre-filled with the old name/path. The readline module now gives the full editing capabilities, e.g., you can even move the cursor by CTRL + ...


-1

Updated since demoting vote so please if this corrects the issue as it looks like when I used a Virtual machine and arch please vote so I get the -1 removed please. If your system uses SUDO see 2nd half below... For Systems that use SU ONLY: In some systems it can be aliased so even if you use su it auto uses su - which forces the use of the new user's ...


2

You can define a trap for SIGINT (triggered by CTRL-C), which will print ^C (or any other text you would like): TRAPINT() { print -n "^C" return $(( 128 + $1 )) } This example is taken from man zshmisc. The return command has the following background: Programs terminated by uncaught signals typically return the status 128 plus the signal number. ...


0

Just thought I'd add this answer in case it helps anyone who's looking for it. If you use chere (which adds a "Bash prompt here" option to the right-click context menu of any folder), you can set it to zsh ("Zsh Prompt Here") with: chere -i -t mintty -s zsh


0

You could use snoopy. It is very simple to install and to remove (no kernel module or patching required). Note that this is not a proper auditing solution and it can easily be circumvented. Disclosure: I am current snoopy maintainer.


0

For me, the problem was not due to a Windows environmental variable %HOME% that I was able to delete. No %HOME% variable was listed in the Environmental Variables dialog box. Instead, I was able to solve the problem in Bitvise by unchecking "Permit environmental variables" in the advanced settings. I also deleted "%HOME%" in the field Initial terminal shell ...


1

The reason this does not work is because zle -U "mc" pushes "mc" onto the input stack, it does not replace the current command buffer. What your widget actually does is: empty line put "mc" on the input stack accept the empty line After the line gets accepted, zsh pulls "mc" from the input stack and puts in the now current buffer. That is why it seems ...


1

One of the "standard" ways to do so, is to use the nohup command, included in coreutils, like this: nohup COMMAND [ARGS] & But the command will redirect the output (STDOUT & STDERR AFAIK) of the program into a file nohup.out, making it somehow annoying sometimes (like generating a huge log file), so you may want to make your own redirection, or ...


5

One solution is to use GNU screen. You could start up screen, run your command, then detach with C-a d. Later, to reconnect, do screen -r, and you are back in your previous session. Other benefits of screen are window management (so you can switch to other shells while your command is running, without needing a new SSH connection), and it allows your ...


20

If your task is already launched, it is too late* to consider alternative solutions that insert an additional layer between your ssh session and the shell running the command, like screen, tmux, byobu, nohup and the likes. If your process support to be placed in the background and particularly doesn't hang when stdout and stderr are unwritable/closed, you ...


0

I suspect you are extracting the archive on a file system that doesn't support file owners and groups and map all of them to root/root.


0

If you can abide python, a simple script will display ASCII values of characters: Create a script (call it for example ascii.py) #!/usr/bin/python import fileinput for line in fileinput.input(): for c in line: print ord(c) then call the script thus: echo "hello" | ascii.py This could easily be modified to total ASCII values.


0

This comes down to the problem of iterating over the letters of a word, which is not trivial in bash. My approach is horribly hacky, but seems to work: #!/bin/bash WORD="$1" REGEXP=''; ASCIISUM=0 while true; do LETTER=$(echo "$WORD" | sed "s/$REGEXP\(.\).*/\1/") test "$LETTER" == "$WORD" && break; ASCII=$(printf '%d' ...


0

Depending on what OS you're on, there's rm -i (which will prompt for each individual file) or perhaps rm -I (part of GNU rm), which, per the man page, will "prompt once before removing more than three files, or when removing recursively. Less intrusive than -i, while still giving protection against most mistakes" I highly recommend against creating an ...


0

The parent process in this case is your current shell. It loads some init scripts when it starts, they can export variables. Check ~/.bashrc, ~/.profile, ~/.bash_profile, ~/.bash_login, and /etc/profile. It can also inherit some exported variables from its parent process back to the init.


1

Thanks for the push, Micah. It got my creative juices flowing. Updated: Tested on Bash 3/4, all builtins, no depedencies: Portability: 100% compatible with Bash 3 and Bash 4 only function _busybox_has() { builtin command -v busybox >/dev/null || return 1 # Sanitize searches for '[' and '[[' a=$1 a=${a//[/\\[} [[ $(busybox) =~ ...


0

If I type # busybox with no parameters I get a list of configured commands that are possible. Depending on your environment you could then parse this string. Grep is mentioned, but lacking that option, I would approach it via the string parsing tools of my environment: bash: options=$('busybox'); if [[ $options == *command* ]] then echo "It's ...


8

What you want is uppercase -I, as in: $ rm -rI tg/ rm: remove all arguments recursively? As noted in the comments, this is something nice GNU's rm is giving you, and not required based on the posix spec for rm.


0

One answer was to use single quotes instead of double quotes, however, that's not quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used. set PS1="$(pwd)" sets the prompt to the working directory as of the set command. set PS1="\$(pwd)" does NOT expand $(pwd). ...



Top 50 recent answers are included