bash

Convert xargs Bash command to PowerShell?

I've got a simple Bash command to resize some images automatically on a low-traffic website using ImageMagick - I'd like to convert this to a PowerShell command so I don't have to install Cygwin on my webserver. Can anyone lend their PSh skills here? ls | xargs -I {} rconvert "{}" -resize 128x128\> "{}" ...

Variables as commands in bash scripts

Hi all, I am writing a very simple bash script that tars a given directory, encrypts the output of that, and then splits the resultant file into multiple smaller files since the backup media don't support huge files. I don't have a lot of experience with bash scripting; I'm believe having issues with quoting my variables properly to al...

Will this redirection ">>& <filename>" work in Korn shell?

I am trying to redirect both STDOUT/STDERR of a UNIX command and append to a log file in a korn shell. rm -rf file1 >>& logfile Will this command work in ksh or is this a typical bash command? What harm would I be causing with above command? ...

Unable to convert Bash script to Zsh script

I need to change the following Bash code to Zsh TODO_OPTIONS="--timeout --summary" cd () { builtin cd "$@" RV=$? [ $RV = 0 -a -r .todo ] && devtodo ${TODO_OPTIONS} return $RV } pushd () { builtin pushd "$@" ...

bash completion for certain types of files in a special directory

I have a list of unison profiles which exists in ~/.unison/*.prf. I'd like to have bash completion so that when I type unison or unison-gtk and hit tab it would list the .prf files from that folder without the .prf part. Perhaps an example would be clearer: $ ls ~/.unison/*.prf default.prf dot-mozilla.prf to-desktop.prf $ cd ~ # ju...

How do I test if a variable is a number in bash?

I just can't figure out how do I make sure an argument passed to my script is a number or not. All I want to do is something like this: test *isnumber* $1 && VAR=$1 || echo "need a number" Any help? UPDATE: I managed (whit Charles' help) to do it, but I'm not yet sure it's the best way to do that (even though it worked on my tests)....

Problem with shell script

Hi all, This is a very simple bash script i wrote: #!/bin/bash ITEM_LIST=items.txt LOG_FILE=log.log TOTAL_ITEMS=$(wc -l ${ITEM_LIST} | awk '{ print $1 }') let NOT_FOUND=0 cat ${ITEM_LIST} | while read item; do grep "${item}" ${LOG_FILE} > /dev/null FOUND=${?} if [ ${FOUND} -ne 0 ]; then let NOT_FOUND=NOT_FOUND+1 ...

load the result of an egrep inside a editor (vim/emacs/gedit)

Hey guys, I got some files, after an egrep command, like egrep -l -r '(this|that|those)' * this will list like, 20 files. I don't want to open each one manually, theres any way that I can redirect the result from grep, directly to an editor? So the editor will open those files to me Thanks ...

How to recursively chmod on subdirectories?

I want to recursively chmod all of the subdirectories below my calcium directory: chmod a+wx calcium How do I change the above command to do this? I believe I'm using bash shell although I'm not sure how to verify this. ...

How do you copy text from Firefox in Windows to bash shell in Unix?

I have a long URL on a web page in Windows that I need to copy into bash shell in Unix. Is there a way to do this without retyping the URL? ...

How to list non-empty subdirectories on linux?

I have a directory containing multiple subdirectories. I want to list only those subdirectories that contain at least one file. How can I do that? ...

Access a variable in a bash script

In the bash command line, I set a variable myPath=/home/user/dir . I created a script in which I put echo $myPath but it doesnt seem to work. It echoes nothing. What can I do to access the myPath variable in the script. If I write echo $myPath in the command, it works, but not in the script. ...

parse an email message for sender name in bash

I have multiple files in a folder and each of them have one email message. Each message has a header in the format Subject: formatting fonts To: [email protected] From: sender name message body I want to get all the unique sender names from all the messages (there is only 1 message per file) . How can I do that? ...

Append git's branch name to command prompt

I wanted to use one of the Git-completion.bash features but I can't customize the look I'd like to have. Here is relevant part of my .bash_profile: source ~/.git-completion.bash function prompt { local WHITE="\[\033[1;37m\]" local GREEN="\[\033[0;32m\]" local CYAN="\[\033[0;36m\]" local GRAY="\[\033[0;37m\]" local BLUE="\[\033[0;34m\]"...

use space as a delimiter with cut command

I want to use space as a delimiter with the cut command. What would be the syntax? ...

In the bash shell, what is " 2>&1 "?

In a unix shell, if I want to combine stderr and stdout into the stdout stream for further manipulation, I can append the following on the end of my command: 2>&1 So, if I want to use "head" on the output from g++, I can do something like this: g++ lots_of_errors 2>&1 | head so I can see only the first few errors. I always have t...

Proper way to run a script using cron?

When running a script with cron, any executable called inside must have the full path. I discovered this trying to run wondershaper, when many errors showed when it tried to call tc. So my question is, what's the proper way to overcome this problem? Possible solutions: cd to the executable folder and prepare symbolic links to any othe...

.bashrc at ssh login

When I ssh into my ubuntu-box running Hardy 8.04, the environment variables in my .bashrc are not set. If I do a source .bashrc, the variables are properly set, and all is well. How come .bashrc isn't run at login? ...

In Unix, how do you remove everything in the current directory and below it?

I know this will delete everything in a subdirectory and below it: rm -rf <subdir-name> But how do you delete everything in the current directory as well as every subdirectory below it and the contents of all of those subdirectories? ...

BASH: Possible to abort shell script if any command returns a non-zero value?

I have a Bash shell script that invokes a number of commands. I would like to have the shell script automatically exit with a return value of 1 if any of the commands return a non-zero value. Is this possible without explicitly checking the result of each command? e.g. dosomething1 if [[ $? -ne 0 ]]; then exit 1 fi dosomething...