Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

8
votes
2answers
2k views

Writing shell scripts that will run on any shell (using multiple shebang lines?)

I've just started getting deeper into shell scripting, and I've always just thrown my script in a file, marked it chmod +x and then done /path/to/script.sh and let whatever interpreter is the default ...
-2
votes
1answer
2k views

Calculate % difference and file sizes between two files

We have two zip files and would like to compare them. We're also interested in calculating the percentage difference between them and the file size. Is there a tool that can do this quickly?
9
votes
3answers
9k views

Passing two arguments to a command using pipes

Usually, we only need to pass one argument: echo abc | cat echo abc | cat some_file - echo abc | cat - some_file Is there a way to pass two arguments? Something like {echo abc , echo xyz} | cat ...
1
vote
1answer
3k views

Removing files older then 1 month, but leave files created at the 1st day of the month

I'm trying to remove some archive files from a folder on a CentOS fileserver with a cronjob. The requirements: Remove files of the last month The .tgz-file of the first day of the month should be ...
8
votes
4answers
6k views

how to grep and print the next N lines after the hit?

I would like to grep for an occurrence in a text file, then print the following N lines after each occurrence found. Any ideas?
3
votes
1answer
555 views

Parse multiple HTML to text and rename as parent Directory

In a directory there are many folders .html inside, I would like all HTML parsed as new .txt with the name of the parent directory. Example1/ Index.html>Example1.txt Example2/ ...
2
votes
1answer
46 views

Creating directory name from file name - strip out non alpha numeric characters and make lower case

I am able to create a directory based on the name of a file. I am running into a wall if the text has spaces or non alpha numeric characters. I would like to strip out those non alpha numeric ...
2
votes
1answer
5k views

Howto switch / chage user id witin a bash script to execute commands in the same script?

Is there a way to switch user identity within a script (executed as root as part of an installation process) to execute some commands without calling an external script, then return to root to run ...
1
vote
3answers
261 views

bash: Use columns separate in an array

Is it possible to put columns separate in arrays, not as a line but as a column. I need to access the lines sequentially. I have one file, but in this example, the files are divided into columns and ...
1
vote
2answers
1k views

couldn't execute “mysql”: no such file or directory, using autoexpect

I have the following file: exp.exp #!/usr/bin/expect db_host='localhost' db_name='webui_dev' db_user='root' db_pass='rootpass' new_db_name='db_2011' expect <<EOF log_user 0 spawn mysql -h ...
1
vote
4answers
405 views

How to extract two numbers from two strings and calculate the difference in Bash?

I have a text file which contains (among others) the following lines: {chapter}{{1}Einleitung}{27}{chapter.1} {chapter}{{2}Grundlagen}{35}{chapter.2} How can I get the 2 lines from this text ...
1
vote
1answer
1k views

Shell script to rename multiple files from their parent folders name

I have a file structure like this: 00000010 000000001.file1 000000001.file2 00000020 00000003.file1 00000003.file2 00000003.file3 ... So there are folders with 8-digit names containing one ...
0
votes
1answer
29 views

Unexpected result from sort command of linux bash

I have a file foo.txt with this content: chr1 15 chr11 5 chr11 8 chr1 7 chr2 23 chr1 35 I tried to sort it first according to the first column, and then according to the second ...
0
votes
1answer
1k views

Problems using EXPECT is a BASH shell script

This is the code (bash script): echo "Pass for router:" read -s pass /usr/bin/expect <<EOD spawn ssh 192.168.10.1 -l root 'opkg list-installed' > list-installed.txt #echo @pass expect ...
0
votes
1answer
109 views

Bash delete file when variable = x

I'm creating a bash script which reboots the system at each reboot it adds a new line to a text file, I then read the text file before each reboot. Once the variable holding the number of lines ...
0
votes
2answers
103 views

Showing a stack of ssh connections in terminal

I had this idea for long time and tried several ways to implement, with no luck. Tried to google many times and always finding not quite what is needed. How to do: $ ssh hostA ...
0
votes
1answer
387 views

Execute a command and put the results into a variable… all in a bash script

I'm working on a bash script that backs up a configuration file before copying over a new file. Here's what my snippet looks like: mv ~/myStuff.conf ~/myStuff.conf.bak cp ~/new/myStuff.conf ...