Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

1
vote
1answer
346 views

How to install a database dump via Shell Script?

I have a Mysql database dump. I want to install it with Hudson via a Shell Script to an external Linux machine. How can you take a Mysql script and run it inside a database on other machine? I know I ...
2
votes
1answer
311 views

reading input in sed

i'm new to shell scripting. I'm learning little by little. I'm more familiar with php which is working toward my disadvantage right now. Anyway, i'm writing a shell script and i read in input with ...
26
votes
3answers
1k views

Should I care about unnecessary cats?

A lot of command-line utilities can take their input either from a pipe or as a filename argument. For long shell scripts, I find starting the chain off with a cat makes it more readable, especially ...
3
votes
2answers
1k views

how to send email as well as display it out

i am trying to run a script with the output to be emailed and watched(monitored), i try using this code: this are the output: >emailmessage echo "output here" >>emailmessage ...
3
votes
2answers
535 views

How to specify -? option with GNU getopt

When parsing command line arguments with GNU getopt command, how do I (if possible) do recognize -? as another option? Is there a way to escape it in the opstring?
3
votes
3answers
13k views

How can I call other shell script like a subroutine?

How do I call an other shell script and wait for its completion? I want to pass input arguments and receive returning result code. And continue running rest of codes.
5
votes
1answer
270 views

Passing clicked links in rxvt to a script

I start my browser vimprobable in tabbed like so: "`tabbed -d > /tmp/tabbed.xid`; vimprobable2 -e `cat /tmp/tabbed.xid`" [1] I am then able to send all new instances of vimprobable to tabbed (and ...
1
vote
1answer
1k views

What does “sudo chown -R hadoop:hadoop hadoop” do?

I saw the following script, posted online, that was used during the hadoop installation process. sudo tar xzf hadoop-0.20.2.tar.gz sudo mv hadoop-0.20.2 hadoop sudo chown -R hadoop:hadoop ...
9
votes
2answers
4k views

Bash: run command2 if command1 fails

I want to do something like this: if cmd1 && cmd2 echo success else echo epic fail fi How should I do it?
2
votes
1answer
296 views

What's wrong with my bash script?

I am trying to utilize zenity in my simple ffmpeg-cut-mp3 script, but it hangs after the input into zenity :/ What's the matter with this? #! /bin/bash start=$(zenity --entry --title="CutMp3" ...
2
votes
2answers
9k views

Executing a shell command from PHP with shell_exec

Included in my thesis is to create an administration interface, in which an administrator can approve users whom have asked for access to use OpenNebula. Upon approval the users should be added to ...
9
votes
4answers
14k views

How to inject keystrokes via a shell script?

I'm trying to inject keystrokes into the input daemon so as to simulate typing from a Bash script. Is this possible, and if so, how can I make it happen?
8
votes
5answers
2k views

Bash CD up until in certain folder

I do a lot of work in Magento, and so do a lot of the people I work with, and it gets annoying to have to type: cd ../../../../../../ To only find you're still a few directories from your root ...
2
votes
2answers
3k views

Using sed to replace a line with many special characters?

I am writing a rather massive script for a project and one of the issues I am running into before I can complete it is using the sed command. I am trying to find a line that has (located in ...
4
votes
1answer
3k views

Debugging shell scripts: Syntax checking without executing

Is there some option I can give to just check the syntax of a [bash] shell script to check the syntax of it, but not actually execute anything nor cause any potential damage?
2
votes
2answers
740 views

Create a new file by removing the new line character at the end of file

I have a flat file which contains the following data records between H: and T:. H:20050427 HEADER RECORD 0000000 00000 000000000 123456 00 654321 DATARECORD 0000000 00000 000000000 123456 00 654321 ...
9
votes
1answer
8k views

File descriptors & shell scripting

I am having a very hard time understanding how does one use file descriptors in shell scripts. I know the basics such as exec 5 > /tmp/foo So fd 5 is attached to foo for writing. exec 6 < ...
26
votes
5answers
3k views

Better way of accepting variations of ‘Yes’ from a shell prompt

Usability testing of a shell script I wrote found that people had different expectations on how to answer a question that expected ‘yes’ as the answer. See variations in the below code example. ...
2
votes
2answers
165 views

Need a script that generates files from words within a single text files

I have the following scenario and my lack of linux knowledge doesn't help a lot. I have a text file that contains YML values, in the following matters: coolregion: min: {z: -99613.0, y: 45.0, x: ...
1
vote
2answers
691 views

writing a command transcript to file

Here is a script from Mercurial issue 2743. Call it mq.sh. I'm trying to get it to do the following things, on Debian squeeze. Echo commands + standard output + standard error to a file. Prefix with ...
7
votes
1answer
368 views

ftp and shebang

Is there a way to shebang-ify ftp and write small ftp scripts? For example: #!/usr/bin/ftp open 192.168.1.1 put *.gz quit Any thoughts?
22
votes
5answers
15k views

Split pages in pdf

I have a scanned pdf file which has scanned two pages on one virtual page (page in pdf file). The resolution is with good quality. The problem is I have to zoom when reading and drag from left to the ...
8
votes
4answers
310 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 ...
13
votes
6answers
6k views

Best way to follow a log and execute a command when some text appears in the log

I have a server log that outputs a specific line of text into its log file when the server is up. I want to execute a command once the server is up, and hence do something like the following: tail -f ...
16
votes
3answers
31k views

How to measure time of program execution and store that inside a variable

In order to find out how long certain operations within a Bash (v4+) script take, I would like to parse the output from the time command "separately" and (ultimately) capture it within a Bash variable ...
5
votes
4answers
1k views

Is there any book , Tutorial on very very advanced shell scripting [closed]

I am looking for some tutorial where a simple script is written using very advanced methods so that i can learn more from
3
votes
2answers
772 views

How to change the target directory for tab completion?

I found a short script to enable note-taking on onethingwell, which includes this: function n { nano ~/n/$1.txt } I'd like to extend it to do tab completion, so that if I want to edit the ...
0
votes
1answer
454 views

How to write script for automatic joomla installation in webhost

I want to create a script in Linux that automatically downloads the latest Joomla from their website and then installs it to the specified user. Is it possible in a shell script? I don't know how it ...
1
vote
5answers
5k views

How to get some part of string in linux

The output of find command is like /home/user/test/folder1/abc.png Now i want to get folder1 from above string
5
votes
3answers
4k views

Why the double quotes and backquotes in a shell script?

I'm looking at this script mysql backup script and I don't understand what is the reason for using both backticks and double quotes around command names? 379 WHICH="`which which`" 380 AWK="`${WHICH} ...
3
votes
7answers
1k views

How to write repeated free-form strings to a file, as fast as 'dd'?

dd can write repeating \0 bytes to a file very fast, but it can't write repeating arbitary strings. Is there a bash-shell method to write repeating arbitary strings equally as fast as 'dd' (including ...
4
votes
1answer
3k views

Why is 'while.. read.. <<EOL' performing variable expansion, yet <file and | don't?

Aside from the variable expansion mentioned in the question's heading, I also experience another alarming issue when reading inline data to <<EOL... When the data contains a backtick `, it ...
4
votes
2answers
496 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 ...
3
votes
1answer
400 views

Multiple renaming files [duplicate]

Possible Duplicate: How to clean up file extensions? I'd like to rename files with extension .flac.mp3 to extension .mp3. I used the following command $ for i in *; do mv $i `echo $i | sed ...
8
votes
6answers
8k views

Find biggest files or directories

Which command will print the sizes of all files and directories in the tmp directory (including hidden ones) and sort them by sizes from largest to smallest in human readable format (e.g. 2 GB)? The ...
1
vote
1answer
4k views

How to run sh from sh file

I developed a Java application. I divided the application into 5 sub-applications, and created a service wrapper to each sub application using shell scripts: subaap1/bin/app.sh subaap2/bin/app.sh ... ...
2
votes
1answer
157 views

Where are the program calls of the boot process stored

I just wrote a little program which logs all calls of bash during the boot process. This is a part of the output produced: (root) '/bin/bash-' '-c' 'gzip -d -c ...
1
vote
3answers
1k views

How do i execute a remote script with 'screens'?

I need to execute a script locally. The problem is, it needs to use screen and send the ctrl d command. How would i do this? The script will be on my local windows machine. i can use winscp, putty, ...
1
vote
2answers
2k views

Creating an empty file having a variable name in a script

I need to create an empty file using a shell script. The filename will be determined by examining all the files in a directory matching a pattern, say TEST.*, and appending _END to it so that the new ...
6
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 ...
4
votes
2answers
5k views

How do I give all the permissions to a file for a single user that's not me?

When I want to grant access to another user to my file, I use chmod 777 file, but if I want to be sure I'm granting permission just for that user, how can I do it? -- update The file is owned by ...
5
votes
2answers
2k views

Mass .flac --> .mp3 transcoding: How to write a shell script that preserves ID3 tag information?

In recent weeks I've gone from a fairly 'hands-on' approach to .flac --> .mp3 transcoding, to one that's far more 'set & forget'. The first step was to stop using a GUI front end (Audacity with a ...
6
votes
2answers
7k views

Why is my variable being localized in one 'while read' loop, but not in another seemingly similar loop [duplicate]

Why do I get different values for $x from the snippets below? #!/bin/bash x=1 echo fred>junk ; while read var ; do x=55 ; done <junk echo x=$x # x=55 .. I'd expect this result x=1 cat ...
3
votes
5answers
3k views

Script to list only files of type ASCII text in the current directory?

How to write a shell script which searches the current UNIX directory and returns the names of all files of type ASCII text?
18
votes
4answers
7k views

How can I detect if the shell is controlled from SSH?

I want to detect from a shell script (more specifically .zshrc) if it is controlled through SSH. I tried the HOST variable but it's always the name of the computer which is running the shell. Can I ...
3
votes
2answers
9k views

How to get the char at a given position of a string in shell script?

How to get the char at a given position of a string in shell script?
4
votes
2answers
1k views

How can I pause in a shell script?

How can I make my shell script pause before continuing?
3
votes
4answers
5k views

Establish openvpn tunnel in bash script

I'm trying to write a script which will establish an openvpn tunnel when the computer boots up. The main problem lies in inputting the pkcs12 password. I realise it's very bad practice to have a ...
6
votes
6answers
4k views

Compare files that are in directory 1 but not directory 2?

I'm having trouble with a bash script I want to make I know ls will list files that are in a directory but I want it to list directories that are in directory1 but NOT in directory2, and then list ...
3
votes
2answers
4k views

How to catch optioned and non optioned arguments correctly?

I want to write a shell script which will take some arguments with some options and print that arguments. Suppose the name of that script is abc.ksh. Usage of that script is - ./abc.ksh -[a ...