bash

Equivalent of `__FILE__`, `__LINE__` in bash

Is there any variable in bash that contains the name of the .sh file executed ? The line number would be great too. I want to use it in error messages such as: echo "ERROR: [$FILE:L$LINE] $somefile not found" Thank you ...

Unwanted Shell expansion when assigning the output of a shell command to a variable

I am exporting a portion of a local prototypte svn repository to import into a different repo. We have a number of svn properties set throughout the repo so I figured I would write a script to list the file elements and their corresponding properties. How hard can that be right. So I write started writing a bash script that would assi...

how to use a bash function defined in your .bashrc with find -exec

my .bashrc has the following function function myfile { file $1 } export -f myfile it works fine when i call it directly rajesh@rajesh-desktop:~$ myfile out.ogv out.ogv: Ogg data, Skeleton v3.0 it does not work when i try to invoke it through exec rajesh@rajesh-desktop:~$ find ./ -name *.ogv -exec myfile {} \; find: `myfile': No...

What is the difference between PS1 and PROMPT_COMMAND

While taking a look at this awesome thread I noticed that some examples use PS1="Blah Blah Blah" and some use PROMPT_COMMAND="Blah Blah Blah" (and some use both) when setting the prompt in a bash shell. What is the difference between the two? An SO search and even a bit of broader google searching aren't getting me results, so ev...

Programmatically getting an access token for using the Facebook Graph API

I am trying to put together a bash or python script to play with the facebook graph API. Using the API looks simple, but I'm having trouble setting up curl in my bash script to call authorize and access_token. Does anyone have a working example? ...

bash arrays - what is difference between ${#array_name[*]} and ${#array_name[@]}

bash-3.00$ cat arr.bash #!/bin/bash declare -a myarray myarray[2]="two" myarray[5]="five" echo ${#myarray[*]} echo ${#myarray[@]} bash-3.00$ ./arr.bash 2 2 both are giving number of elements of array. So what is difference between the two? ...

Stop Search param in directories by grep immediately after param match

hi friends I use the following command to find under /var some param in my script grep -R "param" /var/* 2>/dev/null |grep -wq "param" my problem is that: after grep find the param in file grep continue to search until all searches under /var/* will completed How to perform stop immediately after grep match the param word For exa...

how to find variable is empty or "" in shell script

how to find variable is empty in shell script ...

Next line matching the regex in bash

I have a file in the format: Port Number IP address Port Number IP address (Not sure how the output will be displayed here but let me tell you they are on separate lines) and so on.... I use the command grep -C 1 'port number' file.txt i.e. I want all IP addresses corresponding to a particular port. Making it simple, I want the next...

how to get files as they are added to a remote server

I am using a bash script (below) on a remote server (so far using ssh to connect) to execute a python script that downloads a lot of pdf files one at a time (getting the download locations from a text file with the URL's) in a loop. I would like to move the files from the remote server to my local computer as they are downloaded, and th...

Using RVM with GVim (Cream): rvm command not found.

I am trying to move to GVim(cream) as my primary editor on Ubuntu. I am using the wonderful rails.vim, however I also am using RVM. Rvm works fine when doing things in a shell, and the ruby version I would like to use in rails.vim is the version set as default (but not the system version). When I try to run things like :Rgenerate migr...

Good book for learning Bash shell?

I want to learn how to write shell scripts. Particularly I want to write a svn post-commit script to upload files from a test server to a production server. I am sure I will want to write more as I get more into it. I have very little linux/unix knowledge. Can anyone recommend a good book? ...

How do I set bash environment variables from a script?

I have some proxy settings that I only occasionally want to turn on, so I don't want to put them in my ~/.bash_profile. I tried putting them directly in ~/bin/set_proxy_env.sh, adding ~/bin to my PATH, and chmod +xing the script but though the script runs, the variables don't stick in my shell. Does anyone know how to get them to stick a...

Having trouble with post-commit hook

I am following this tutorial that is like the hello world for post-commit I am using unbuntu 10.04. I installed svnnotify and ran $ which svnnotify which output: /usr/bin/svnnotify so I changed the path in the turorial from /usr/local/bin/svnnotify to /usr/bin/svnnotify I also tried changing the line: #!/bin/sh to #!/bin/bash si...

bash script code help to make zip/tar of several folders .

I am very new in bash and never coded in before but this task is stuck so need to get rid of it . I need to make bash script to make a single compressed file with several dirs. Like - /home/code/bots/ /var/config/ . . . /var/system/ and all will be compressed to single file /var/file/bkup.[zip][tar.gz] Thanks in advance ...

bash: flushing stdin (standard input)

I have a bash script that I mostly use in interactive mode. However, sometimes I pipe in some input to the script. After processing stdin in a loop, I copy a file using "-i" (interactive). However, this never gets executed (in pipe mode) since (I guess) standard input has not been flushed. To simplify with an example: #!/bin/bash while ...

How to "serialize" and "deserialize" command line arguments to/from string?

I call my script: $ ./script 'a!#*`*& ^$' "sdf sdf\"qw sdsdf" 1 -- 2 3 It gets arguments: 1: a!#*`*& ^$ 2: sdf sdf"qw sdsdf 3: 1 4: -- 5: 2 6: 3 If I need to call something with the same arguments locally, I do this: someprogram "$@" But how can I put all that array to a string (to store in file or in environment variable or pas...

How to print value of a variable (which can be "-n" or "-e") in bash?

How to print "-n", "-e" or "-neeenen" from bash (without a newline at the end, without invoking of external programs)? Q="-n" echo -n "$Q" # fail echo -- "$Q" # fail cat <<< "$Q" # fail, also starts external program printf -- '%s' "$Q" # success, but starts external program ...

Incremental deploy from a shell script

I have a project, where I'm forced to use ftp as a means of deploying the files to the live server. I'm developing on linux, so I hacked together a bash script that makes a backup of the ftp server's contents, deletes all the files on the ftp, and uploads all the fresh files from the mercurial repository. (and taking care of user upload...

Having trouble writing my first bash script

ok I am writing my first bash script in ubuntu 10.04. The file is on my desktop: /home/myuser/Desktop The file is called hello-world The file contains: #!/bin/bash echo "Hello World" I open a command line and run: /home/myuser/Desktop/hello-world It tells me permition is denied. So I run it again with sudo, it asks me for my ...