I would like to extract the current path in a variable and use it later on in the script
Something like:
myvar = pwd
Later on:
cd myvar
But my bash skills have rusted over the years.
How would i go on about doing that?
...
I use netbeans 6.8 beta and when i load .sh (bash) file it's not colored at all. i can add a new file association for the .sh extension but it doesn't seem that there is a known associated mime type.
...
I need a variable to hold results retrieved from the database. So far this is basically what I'm trying with no success.
myvariable=$(mysql database -u $user -p $password | SELECT A, B, C FROM table_a)
My understanding of bash commands is not very good as you can see.
...
I feel like this should be simple, but can't figure it out: What's the bash command(s) to look through a folder and open the largest file using VIM?
...
The code is from here
I tried it,but it generates the same icon to me!
EDIT
to be more specific,I want to create an icon like
#!/usr/bin/env bash
nargs=$#
if [ $nargs -eq 0 ]
then
echo "Error - No arguments provided !"
echo ""
echo "animate converts rectangular image to a scrolling animated gif"
echo "Usage : "
e...
I've been trying to automate some configuration backups on my cisco devices, i've already managed to do the script that accomplishes the task but I'm trying to improve it to handle errors too.
I think that's necessary to catch the errors on two steps, first just after the 'send \"$pass\r\"' to get login errors (access denied messages) a...
Okay, so I'm learning Bash, and there's that exercise;
"Write a script that checks every ten seconds if the user 'user000' is logged in."
My idea is to grep a who, but I don't know how to incorporate this into a script. I tried things like
if [ `who | grep "user000"` ] then things
but it returns the matched lines with grep, not true...
I'm trying to split a large log file, containing log entries for months at a time, and I'm trying to split it up into logfiles by date. There are thousands of line as follows:
Sep 4 11:45 kernel: Entry
Sep 5 08:44 syslog: Entry
I'm trying to split it up so that the files, logfile.20090904 and logfile.20090905 contain the entries.
I'v...
How can you convert the following command for Ubuntu's ZSH?
DavidPashley's command for Bash
trap 'echo -e "\e]0;$BASH_COMMAND\007"' DEBUG
if [ "$SHELL" = '/bin/bash' ]
then
case $TERM in
rxvt|*term)
set -o functrace
trap 'echo -ne "\e]0;$BASH_COMMAND\007"' DEBUG
export PS1="\e]0;$TERM\00...
I have a bash script that installs some software. I want to fail as soon as possible if it is not being run by root. How can I do that?
...
I have a procedure I want to initiate only if several tests complete successfully.
One test I need is that all of my NFS mounts are alive and well.
Can I do better than the brute force approach:
mount | sed -n "s/^.* on \(.*\) type nfs .*$/\1/p" |
while read mount_point ; do
timeout 10 ls $mount_point >& /dev/null || echo "stale...
For testing purposes I have this shell script
#!/bin/bash
echo $$
find / >/dev/null 2>&1
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
Running it in the background, and killing the shell only will orphan the commands running in the scr...
I'm writing a script to do variable substitution into a Java properties file, of the format name=value. I have a source file, source.env like this:
TEST_ENV_1=test environment variable one
TEST_ENV_2=http://test.environment.com/one
#this is a comment with an equal sign=blah
TEST_ENV_3=/var/log/test/env/2.log
My script will replace eve...
I am trying to loop through a directory of text files and combine them into one document. This works great, but the text files contain code snippets, and all of my formatting is getting collapsed to the left. All leading whitespace on a line is stripped.
#!/bin/sh
OUTPUT="../best_practices.textile"
FILES="../best-practices/*.textile"
fo...
I was hoping:
cp -R src/prog.js images/icon.jpg /tmp/package
would yield a symmetrical structure in the destination dir:
/tmp
|
+-- package
|
+-- src
| |
| +-- prog.js
|
+-- images
|
+-- icon.jpg
but instead, both of the files are copied into /tmp/package. A flat copy.
(This is on OSX).
...
Why does the following...
c=0; for i in $'1\n2\n3\n4'; do echo iteration $c :$i:; c=$[c+1]; done
print out...
iteration 0 :1 2 3 4:
and not
iteration 0 :1:
iteration 1 :2:
iteration 2 :3:
iteration 3 :4:
From what I understand, the $'STRING' syntax should allow me to specify a string with escape characters. Shouldn't "\n" be in...
I have the following snippet in a bash script:
db2 connect to $DB
var=$(db2 -x "$query" | tr -d " ")
$query holds a select count query, -x just prints out the result of the command with no headers so var would be assigned to a number.
What happens is that $(...) is executed in a subshell and doesn't inherit the connection to DB2 resu...
Hi,
I am trying to implement a simple log server in Bash. It should take a file as a parameter and serve it on a port with netcat.
( tail -f $1 & ) | nc -l -p 9977
But the problem is that when the netcat terminates, tail is left behind running. (Clarification: If I don't fork the tail process it will continue to run forever even the ...
This is weird and I'm not sure who the culprit really is.
I'm doing some scripting, on FreeBSD (6.2)? which makes extensive use of the following bashism:
do_something <(mysql --skip-column-names -B -e 'select ... from ... where ...;')
... where "do_something is a somewhat crufty utility (in Perl) that won't read from a pipeline. If ...
How can I recursively change xxx-xxx_[a-zA-Z]+_\d+_(\d+)\.jpg into $1.jpg?
...