A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

learn more… | top users | synonyms (1)

3
votes
1answer
4k views

auto accepting rsa key in bash script

I have done a little googling and have not come up with a clear answer to this question. I was wondering if someone could help me out with this issue. Is there a way to auto accept any RSA key inside ...
0
votes
1answer
227 views

sudo nt passing after redirection operator [duplicate]

Possible Duplicate: sudo permission denied but su grants permission I am trying to echo a new value into a file using following command sudo echo 4096 > /proc/sys/fs/file-max The ...
7
votes
2answers
933 views

How to do a text replacement in a big folder hierarchy?

I want to search and replace some text in a large set of files excluding some instances. For each line, I want a prompt asking me if I need to replace that line or not. Something similar to vim's ...
8
votes
4answers
312 views

Do you prefer bash scripts or aliases for shortcuts?

I have a ~/bin directory (which is on my PATH) where I store a lot of little 1 or 2 line scripts. Some of them just cd into a directory and run a command on a file, like vim or something. But I also ...
4
votes
3answers
7k views

checking an argument to a bash script is a string of all digits

The Bash FAQ says If you're validating a simple "string of digits", you can do it with a glob: # Bash if [[ $foo = *[!0-9]* ]]; then echo "'$foo' has a non-digit somewhere in it" else echo ...
2
votes
3answers
536 views

Batch File Rename Using Mapping File

I have a large collection of image files, for example: a.png, b.png, c.png, etc If I have a file with mappings of filenames to numbers, like so (ignore the format, it could be anything): a=>1 ...
4
votes
2answers
824 views

bash script is trying to execute a variable

I have a very short Bash script, like this: variable="3 things" if $(echo $variable|grep "^[0-9]\{1,\}") #if $variable begins with [0-9] then echo $(echo $variable|sed 's/ .*$//') else echo ...
19
votes
5answers
854 views

shebang and path

Why does a shebang need a path? Wrong #!ruby Correct #!/usr/local/bin/ruby #!/usr/bin/env ruby The operating system should have the information regarding the path for a registered command, and ...
8
votes
1answer
463 views

Command to move a window to all desktops

I'd like to be able to move (pin) an existing window to all desktops using a scriptable command, rather than through the window menu. wmctrl -r <WIN> -t <DESK> will move a window to a ...
2
votes
1answer
211 views

starting from last line processed when processing log file several times

I am designing a logging and reporting system for a web application. Within the web application some events can happen ("user logged in", "user performed action X", etc..). I would like the ...
3
votes
5answers
2k views

Replacing text from a list of replacements. Added complication: backslashes

I have a file A that contains pairs of strings, one per line: \old1 \new1 \old2 \new2 ..... I would like to iterate over file A, and for each line perform the replacement (e.g. "\old1 -> \new1") ...
4
votes
2answers
510 views

Shell script printing the most visited directories

Is there a way to write a bash script with the following functionalities? Be launched when I press some key or key combination. (not so important requirement) Identify the 7 most visited directories ...
4
votes
2answers
788 views

find arcana: can't get pipe to work in -exec line

How do I pipe the results of a find through a sed to xform the stream, and then use that transformed stream as one of two arguments to a script? IE: find turns up file1.tiff (among others) sed ...
7
votes
3answers
4k views

How to run a script from another path, and know the script's path?

I need to run a script that access a file in the same path it is located. For example: I have the script in /home/me/folder/script.sh, and this script will access the file /home/me/folder/myfile. As ...
7
votes
6answers
14k views

How to run commands in batch mode over ssh?

How can I run commands in batch mode over ssh? That is, what is the ssh command's equivalent of sftp -b <filename> <hostname>? I have a set of commands which I wish to run across a set of ...
4
votes
3answers
542 views

Best directory for shared scripts

What is the conventional directory to keep shared scripts that might be used by more than one user? I've read through this overview of the standard file system hierarchy, but it doesn't seem to ...
5
votes
7answers
5k views

get numeric ASCII value for a character

I'm trying to write a shell script which asks for an ASCII character in the range A-Z or a-z and returns its equivalent numerical value. For example, the output might look like the following: ...
42
votes
8answers
57k views

Looping through files with spaces in the names?

I wrote the following script to diff the outputs of two directores with all the same files in them as such: #!/bin/bash for file in `find . -name "*.csv"` do echo "file = $file"; diff ...
3
votes
4answers
2k views

stty: : Invalid argument

I am telnet-ing into a Solaris machine and I'm getting the above error with my scripts. I realize this is a common problem, and the solution is to check for the line 'stty erase ^H' within my profile, ...
11
votes
6answers
5k views

What are good online resources for learning shell scripting? [closed]

I am a beginner to shell scripting. I have not yet hardly coded a single program, but I am interested in learning it completely. Can anyone suggest some good online resources which will guide me?
2
votes
2answers
914 views

How do I prevent expansion when I use a pattern as argument to a script?

I need a very simple script which does this: mogrify -resize $1x$2^ -gravity center -crop $1x$2+0+0 $3 so that I can call it in this way: cropresize.sh 110 110 *.png the problem is that the ...
0
votes
2answers
1k views

Why curl -O -C on mac fails to download

The following script works on Ubuntu, but not on Mac. Why? How to edit it so that it would work there too? #!/bin/sh v=1.1 test_file="Test10.java" jar_file="dp4j-$v-jar-with-dependencies.jar" curl ...
5
votes
4answers
5k views

Can IFS (Internal Field Separator) function as a single seperator for multiple consecutive delim chars?

Parsing an array using IFS with non-whites space values creates empty elements. Even using tr -s to shrink multiple delims to a single delim isn't enough. An example may explain the issue more ...
4
votes
4answers
711 views

How to make functions created in a bash script persist like those in .bashrc?

My .bashrc was getting a little long, so I decided to break it up into smaller files according to topic and then call these files from within .bashrc as so #my long .bashrc file bash .topic1rc bash ...
5
votes
4answers
3k views

Copy a File From One Zip to Another?

I have a file named 'sourceZip.zip' This file ('sourceZip.zip') contains two files: 'textFile.txt' 'binFile.bin' I also have a file named 'targetZip.zip' This file ('targetZip.zip') contains ...
5
votes
2answers
986 views

How does bash interpret the equal operator with no surrounding spaces in a conditional?

The following script does not behave as I would have expected. Adding spaces around the '=' in the conditional made it perform how I wanted, but it got me thinking, what is it actually doing inside ...
2
votes
1answer
952 views

Download and install latest deb package from github via terminal

I would like to download and install the latest .deb-package from github (https://github.com/elbersb/otr-verwaltung/downloads to be exact). How can I download the latest package (e.g. ...
15
votes
7answers
10k views

Faster way than ping for checking if computer online?

I'm writing a wake on lan script for a set of our lab computers. We have sqlite db with a list of the computer hostnames, IPs, and MACs and currently I ping each of them with '-c1' so it doesn't run ...
5
votes
1answer
1k views

Bash script IDE

Is there a bash/ksh/any shell script IDE. Don't you get annoyed when you forget the space inside if or I don't know, some minor syntax mistakes you do from time to time, but takes you a long time to ...
4
votes
1answer
382 views

In Gnu Emacs how do I set up a global key to toggle the menu-bar?

Using Gnu Emacs 23.1.1 on Ubuntu 10.04... I'm currently a total newb with emacs, and I've decided to go cold turkey with the Gnome menu bar. (but I do want it to be "available" for the teething ...
5
votes
1answer
2k views

Bash flush standard input before a read

Is there an easy way in bash to flush out the standard input? I have a script that is commonly run, and at one point in the script read is used to get input from the user. The problem is that most ...
1
vote
2answers
2k views

Fluxbox shortcut to open an xterm, or switch to an existing one

Is it possible using fluxbox to setup up a shortkey to say winkey+r that opens up a terminal (say xterm or whatever) with these properties: If there is already a terminal that the working directory ...
4
votes
3answers
6k views

How can i check that a remote computer is online for ssh / script acess?

i'm writting a script that will backup data from my laptop to an ubuntu server. to do so, i'm looking for a (ba)sh command to test if the server is available before starting the backup. something like ...
2
votes
2answers
446 views

Copy a file from a nautilus-script to clipboard

I have a nautilus script that generates an archive file based on the files selected in the nautilus window. This archive file is created in the /tmp directory. I want a way to copy this file to the ...
6
votes
4answers
10k views

Processing bash variable with sed

Been banging my head off a wall on this bash variable LATLNG contains a latitude & longitude value in brackets like so (53.3096,-6.28396) I want to parse these into a variable called LAT and ...
6
votes
2answers
10k views

Excluding a directory when zipping files

I've got a bash script that does something like this: zip -0 ../backup/backup.zip \ -r ./* \ -x \*CVS\* \ -x *Thumbs.db* \ The directory it's backing up is a SVN archive (it used to be CVS back in ...
3
votes
10answers
3k views

Is there a scripting language with C-like syntax?

I can neither code Bash nor Python (actually, I am only comfortable with C-like syntax), and, actually, am too busy and lazy to learn them now. But I would like to script some tasks. Is there a ...
7
votes
2answers
3k views

Iterate over the output of a command in bash without a subshell

I want to loop over the output of a command without creating a sub-shell or using a temporary file. The initial version of of my script looked like this, but this doesn't work since it creates a ...
5
votes
3answers
6k views

History command inside bash script

I have been bashing my head to write a simple history script for the last two days. History is a shell-built in command I couldn't able to use that within a BASH script. So, Is there a way attain this ...
4
votes
2answers
530 views

retrieving names of all open pdf files (in evince or otherwise)

I constantly have many PDF files open. These are usually downloaded using chrome and immediately opened using evince. I sometimes want to persist the state of all my open PDF files, so I could ...
2
votes
1answer
1k views

Bash Conditional Statements

What are the three formats of conditional statements used in bash scripting?
5
votes
2answers
269 views

Collect files using find

I currently have this script: find . -name '*.log' -print0 | xargs -0 tar zcf $file To collect all the "*.log" files. I would like to modify it to include also all the ".txt" files but I don't know ...
4
votes
3answers
264 views

Best way to work through / display a tree of images sorted by size

I've got a deep directory tree containing .PNG files. I'd like to find all the .PNG files in the directory, sort them in order of size from smallest to largest, and then display every 50th image. ...
10
votes
1answer
2k views

How do I make a shell script that sends output to a process

I'm currently running a server console program in a screen because I need to both read it and occasionally send commands. I'd like to run the app as a deamon in the background (start/stop it with ...
5
votes
1answer
938 views

Batch importing .sql files

I have a bunch of .sql files in a directory that I need to import. Although I can do it manually, for scripting purposes I need to be able to apply them in bulk. How can I do that though? What ...
5
votes
3answers
15k views

Storing output of command in shell variable

I have an operation using cut that I would like to assign result to a variable var4=echo ztemp.xml |cut -f1 -d '.' I get the error: ztemp.xml is not a command The value of var4 never gets ...
19
votes
10answers
8k views

Object-oriented shell for *nix

Preface: I love bash and have no intention of starting any sort of argument or holy-war, and hopefully this is not an extremely naive question. This question is somewhat related to this post on ...
7
votes
6answers
6k views

Extracting nested zip files

I have numerous zip archives, each of which contains a number of zip archives. What is the best way to recursively extract all files contained within this zip archive and its child zip archives, that ...
6
votes
1answer
2k views

Reason for ksh obsoleting -eq

The latest version of ksh obsoletes using -eq within [[ ]] blocks, prefering (( )) instead. Why is this? I can't find any documentation on the advantages of (( )) over [[ ]] anywhere, and I find that ...
1
vote
0answers
866 views

Which scripting language is most widespread in system administration tasks? [closed]

I am migrating to Linux and have some experience with the Mac OS X command line/bash. I'd like to automate system admin tasks via scripting, but I am unsure as which language is the most used in the ...