bash

Basic bash script variable declaration - command not found

This seems like such a simple question I'm embarrassed to ask it: test.sh #!/bin/bash STR = "Hello World" echo $STR when I run sh test.sh I get this: test.sh: line 2: STR: command not found What am I doing wrong? I look at extremely basic/beginners bash scripting tutorials online and this is how they say to declare variables... S...

Can we change the day and time of a schedule task which is already created

I have already created a schedule task which runs weekly on some day(wed). I want to change the day and the time of the same task. Is it Possible? If it is not possible, then delte the current scehdule task first and recreate a new one is the solution? ...

Bash Script Calls another bash script and waits for it to complete before proceeding

I have 1 bash script that runs another bash script, however the first bashscript isn't waiting for the second one to complete before proceeding, how can I force it to wait? For example: #!/bin/bash # first.sh #call to secondary script sh second.sh echo "second.sh has completed" echo "continuing with the rest of first.sh..." The way...

How to perform shell "for" command over files with spaces in names?

I find myself frequently doing the following: for f in `find -foo -bar -baz`; do process "$f" done This of course doesn't work for file names with spaces. How can I handle such cases? ...

email from bash script

#!/bin/bash MESSAGE="Line one. /n" MESSAGE="$MESSAGE Line two. /n" MESSAGE="$MESSAGE Line three." echo $MESSAGE | mail -s "test" "[email protected]" Is that how I should get each line, on its own line? ...

create emacs alias that starts in background?

Hi, I have an alias in bash that runs emacsclient if emacs daemon is already running and start emacs otherwise. However, in the event that a fresh instance of emacs is fired up, can I make it run in the background so I can still use that terminal (or close it)? In my bash profile, I have alias ec="/usr/bin/emacsclient.emacs-snapshot -n ...

Bash alias to Python script -- is it possible?

The particular alias I'm looking to "class up" into a Python script happens to be one that makes use of the cUrl -o (output to file) option. I suppose I could as easily turn it into a BASH function, but someone advised me that I could avoid the quirks and pitfalls of the different versions and "flavors" of BASH by taking my ideas and mak...

How do I edit the output of a bash script before executing it?

For example look at the following line of bash-code eval `echo "ls *.jpg"` It lists all jpgs in the current directory. Now I want it to just print the line to the prompt so I can edit it before executing. (Like key-up does for example) How do I do that? The reason for this question comes from a much more usefull alias: alias ac...

Unix commandline history substitution ^foo^bar (for multiple replacements)

Occasionally I use the bash command to replace string in previous command: ^foo^bar Today I wanted to make the replacement in the following line for replacing all occurrences of checkbox with `radio: $ git mv _product_checkbox_buttons.html.erb _product_checkbox_button.html.erb $ ^checkbox^radio git mv _product_radio_buttons.html.erb ...

How to echo directories containing matching file with Bash?

I want to write a bash script which will use a list of all the directories containing specific files. I can use find to echo the path of each and every matching file. I only want to list the path to the directory containing at least one matching file. For example, given the following directory structure: dir1/ matches1 matches...

bash case statements evaluate to strings

I've caught the functional programming bug, so naturally nothing is good enough for me anymore. ;) So, in bash one could write: case $status in "foo") status="bar" ;; "baz") status="buh" ;; *) status=$status ;; esac but I'm afraid of typos, so I'd prefer to write: status=case $status in "foo") "bar" ;; "baz") "buh" ;; *...

BASH: How do you "split" the date command?

Cygwin user here (though if there's a suitable solution I will carry it over to K/Ubuntu, which I also use). I have a Welcome message in my .bashrc that looks like the following: SAD=(`date +%A-%B-%d-%Y`) DUB=(`date -u +%k:%M`) printf "Today's Date is: ${SAD}.\n" printf "Dublin time is now ${DUB}. (24-Hour Clock)\n" After numerous at...

Remotely run command in local X session?

I have an HTPC (with an HDTV as the monitor) running Ubuntu Karmic, and various other computers in the house. Sometimes I want to run X11 applications (usually, but not always, XBMC) on the HTPC displayed on the HDTV, but I don't want to have to physically go to the HTPC to do so; I want to do so from another computer in the house. If I...

Is there a convention for naming 'private functions' in bash?

Is there a convention for naming private functions in bash? I have a bash module with some private functions, wondering if I should start their names with underscore. So far I haven't seen any convention. ...

Making linux "Wait" command wait for ALL child processes

Wait is not waiting for all child processes to stop. This is my script: #!/bin/bash titlename=`echo "$@"|sed 's/\..\{3\}$//'` screen -X title "$titlename" /usr/lib/process.bash -verbose $@ wait bash -c "mail.bash $@" screen -X title "$titlename.Done" I don't have access to /usr/lib/process.bash, but it is a script that changes fre...

How to write a bash script to get the time on another linux server?

Does anyone know how to write a bash script that will pull the time off of another server? I need a script that will poll the other server's time and start an event at a very specific period of time based on the time on the external server. ...

How to silent output in a BASH script?

I have a program that outputs to stdout and would like to silence that output in a bashscript while piping to a file. For example, running the program will output: % myprogram % WELCOME TO MY PROGRAM % Done. I want the following script to not output anything to the command-line: #!/bin/bash myprogram > sample.s How would I do this...

Is it possible to do a grep with keywords stored in the array?

Hello, Is it possible to do a grep with keywords stored in the array. Here is the possible code snippet... Please correct it args=("key1" "key2" "key3") cat file_name |while read line echo $line | grep -q -w ${args[c]} done At the moment, I can search for only one keyword. I would like to search for all the keywords which is stored...

Highlighting python stack traces

Hi all, I'm working on quite complex project and time after time I have to narrow down problems looking at stack traces. They happen to be very long and involve “my” code, standard library code and 3rd party libraries code at same time. Most of time the real problem is in “my” code and locating it instantly in a stack trace is a bit har...

What is the proper indentation for bash scripts?

What is the proper indentation for a bash script? As a java/c++ monkey I religiously indent my code. But it seems you are not allowed to indent this code: #! /bin/bash if [ $# = 0 ] then # there was no arguments => just do to standard output. echo "there are no parameters" else cat << EOF =============================...