Scripts written in the bash shell language. Most questions should use the tags /bash and /shell-script instead.

learn more… | top users | synonyms

2
votes
2answers
116 views

printf output running over into next line

I have created Bash SS in vi. My output is running over into the line below it. I am new to UNIX so I'm trying to learn. My output is displayed using printf. printf "%-15s %15s %15s %2d\n %2s " ...
11
votes
3answers
307 views

Variable as command; eval vs bash -c

I was reading a bash script someone made and I noticed that the author doesn't use eval to evaluate a variable as a command The author used bash -c "$1" instead of eval "$1" I assume using eval ...
0
votes
0answers
7 views

Loading of PNG image through CGI program failing with errors [migrated]

I am writing to write a cgi script to display a png image in a browser. When user clicks on the 'Submit' form in the HTML page , the CGI program is called to display the image . But this is not ...
2
votes
1answer
47 views

Multiplex bash function execution

I created a bash function to "automagically" connect on our switches and retrive their startup-config using the expect command. I have to use expect because this switch does not accept the ssh ...
1
vote
2answers
54 views

shell script to find the combination of the array elements

I have a shell script in which I have defined an array. The array contains more than 2 elements. I need to find the combination of all the elements in my array. Suppose, if my array has the elements, ...
0
votes
2answers
33 views

command condition sometimes integer sometimes string

I want to execute this condition while [ $(cat /path_of a file/) -eq 1 ] The condition is only correct if $(cat /path_of a file/) is an integer and not a string ! How can I overcome this ...
8
votes
4answers
309 views

Using “${a:-b}” for variable assignment in scripts

I have been looking at a few scripts other people wrote (specifically Red Hat) and a lot of their variables are assigned using the following notation VARIABLE1="${VARIABLE1:-some_val}" or some expand ...
8
votes
6answers
434 views

A bash function that takes argument like other languages?

I have a bash function to set the $PATH like this -- assign-path() { str=$1 # if the $PATH is empty, assign it directly. if [ -z $PATH ]; then PATH=$str; # if the $PATH does ...
0
votes
1answer
34 views

How to pass a flag from one script to a function in another script

I have a script that installs a bunch of programs (homebrew, git, etc) and I have it log to stdout all the things that its doing along the way, but I want the ability to pass a flag, such as --no-log ...
3
votes
3answers
74 views

Bash, how to let some background processes run but wait for others?

I have (yet) another wait, &, && control flow question.. Say I have a script something like this where I want to do as much work at the same time as possible: # may take some hours ...
-1
votes
2answers
68 views

Add users from dat file

I have a dat file with names. These are the names of users I must add, without groups or passwords. Ofcourse i have to remove all spaces. I have to add them with a bash script. Can anyone help me ...
6
votes
4answers
378 views

How to run parallel processes and combine outputs when both finished

I have a bash shell script in which I pipe some data through about 5 or 6 different programs then the final results into a tab delimited file. I then do the same again for a separate similar dataset ...
2
votes
1answer
29 views

Turning off default video output with xrandr when external monitor is connected

I'm new to bash scripting, and I'm trying to configure my video outputs so that my laptop display gets turned off when I connect an external monitor via VGA. That's the script I came up with, pretty ...
2
votes
3answers
63 views

purpose of run-parts(8) utility

At least under Debian-based systems, there is a run-parts utility in debianutils package which is used in various scripts. For example in /etc/X11/Xsession. It will run all the executable files found ...
2
votes
1answer
87 views

Bash Script getting stuck during execution

I have a bash script that is reading a CSV file , that contains source IP address , destination IP address and destination port. My script is basically doing 2 tests: 1 Performance 2 Connectivity. ...
3
votes
1answer
172 views

Need help decoding bash script

Have following line in bash script, parsing input arguments: ((10#$2 > 0)) 2>/dev/null && shift 2 || shift Basically it helps handling parameters with optional integer subparameter. ...
2
votes
2answers
65 views

redirecting to /dev/null

I'm reading an example bash shell script: #!/bin/bash # This script makes a backup of my home directory. cd /home # This creates the archive tar cf /var/tmp/home_franky.tar franky > /dev/null ...
-4
votes
3answers
129 views

How to get IP Address using shell script? [duplicate]

Want to get the IP address using Shell script. Without knowing the eth0 or eth1 or eth2 How to get the particular IP address. I am not interest to get localhost address, want to get private IP ...
-4
votes
4answers
84 views

How to add a 3 lines in a file using shell script? [closed]

I have a file, that file contain 10 lines. And now I want to add 3 lines to end of the file using shell script. After add lines, If I run the script again I don't want to add same lines again. ...
1
vote
5answers
69 views

Command for display of Memory usage, Disk Usage and CPU Load

I want to diplay the Memory usage, Disk Usage and CPU Load in the following format: Memory Usage: 33/512MB (6%) Disk usage: 4.2/20GB (23%) CPU Load: 0.01 How can I do that?
4
votes
4answers
137 views

How do I make sure that a script is run exclusively? [duplicate]

So I have a bash scripts that does some things (pull from github, delete folders .. etc ..) pretty basic stuff. I usually run it whenever I need a new version of the web app on the server. The thing ...
0
votes
2answers
77 views

How to write an alias function to make dd show progress bar?

According to this article, by replacing: $ dd if=/dev/sda of=/dev/sdb [additional options] with: $ pv -tpreb /dev/sda | dd of=/dev/sdb [additional options] one can augment the default dd ...
0
votes
2answers
130 views

Are there any well known and well used shell scripting IDEs for Un*x?

Are there any IDEs targeted at shell scripting, specifically bash and zsh scripts? This means having syntax-highlighting for shell scripts and more importantly debugging environments with features ...
1
vote
3answers
159 views

How to loop a read function in Bash Script?

I needed to remove spaces and capital letters to various strings of text like: "My Name is Mauro" -> "my_name_is_mauro" So I have created this bash script:lowercase_underscore.sh (call it the ...
2
votes
1answer
48 views

bash script - need date command variable

I am trying to create a script that will parse the /var/log/secure file for failed login attempts for today's date only and redirect those attempts into a separate file so I can view those attempts ...
2
votes
2answers
47 views

Bash script to signal a concurrently running instance (same script) about a condition and increment counter

Background Here's what I want to achieve. I have a (potentially) long-running process. Now I have locking in place just fine and all is generally in order. However, since this is a scheduled job, ...
4
votes
7answers
202 views

How to detect the desktop environment in a bash script?

I am writing a bash script that needs to know which desktop environment (XFCE, Unity, KDE, LXDE, Mate, Cinnamon, GNOME2, GNOME3,... ) is running. How can I obtain that information?
1
vote
0answers
27 views

manipulate a Drush “internal” variable

I want to modify a variable (preferably in a Bash Script format) because my PHP environment requires a port number. To show a URL in Drush containing a token that logs you in as user 1 (without a ...
0
votes
1answer
37 views

Is it a bad idea to keep scripts in /root? [closed]

Is it a bad idea to keep scripts in /root? Simple bash scripts that have the following permissions: -rw-r--r-- They execute fine when ran as root, but is this bad practice? It's a multi-user system, ...
2
votes
2answers
85 views

Interactively concatenate video files

Problem : How to concatenate (join) multiple MP4 video files into one file interactively? There are a lot of programs that do this for two files from the command line. For instance : ffmpeg, ...
0
votes
1answer
34 views

Using !n in script or interactive mode

I add to ~/.bashrc the following code: test_exclamation () { printf %s "$READLINE_LINE" | xargs echo } bind -x '"\eX": test_exclamation' I write to bash prompt buffer $ !1700 If I press Enter, ...
1
vote
3answers
55 views

Copy command from history to bash prompt

Sometimes I'd like to get some command from history output, copy it to bash prompt, make some changes and run it. Is there a way to copy command from a history output to bash prompt without involving ...
1
vote
0answers
45 views

Editing the .profile file to access

I am trying to source my .profile file to easily access a directory of javatools. The bash code below seems like it should work but it does not. Any help troubleshooting this script would be very much ...
0
votes
1answer
69 views

Bash script for copying text currently entered to prompt

I'm trying to minimize using of mouse. Copying text in terminal is the mostly inconvenient activity for mouse avoiding. Now, tmux helping me to obtain this purpose. However, I regularly needs to copy ...
1
vote
1answer
60 views

Bash Script which can direct stdin stream to program

I am trying to create a script capable of infinitely processing an incoming stream which is piped to it, and continuous producing an output stream which can be piped to something else something as ...
2
votes
1answer
123 views

BASH : Array as String Buffer

Instead of displaying (or writing) every result once generated, i designed an Array based Buffer to store data and write it whenever the line counter reaches a MAX value. Here is the script : ...
2
votes
1answer
48 views

Can I apply `tmux` to a bash script?

Is it possible for me to use tmux to SSH into a Raspberry Pi, run a Bash script, and then leave the session (from my laptop), while the Raspberry Pi continues to run the script?
2
votes
1answer
157 views

How to strip color codes out of stdout and pipe to file and stdout

I have a program that uses printf with some tput mixed in it and I'd like to pipe the output to stdout as well as a file. I'd prefer to use sed since I don't want any unnecessary dependencies on my ...
1
vote
4answers
74 views

How to get started with bash? [closed]

I need a way to be able to run a script that will automate terminal commands, one after another. As I understand it, this is exactly what bash does. (Am I right, even on this count?) Where can I ...
0
votes
1answer
40 views

How I append the data of Multiple files into one file?

I want to append data of approx 500 files into one file and each of these files are located in their respective dirs. Also How i can verify the contents of merged file e.g How i verify that data ...
5
votes
5answers
109 views

A shell script to write selected fields to a single line

I have a log file trace.log which prints the time stamp, thread name and Transaction method and transaction ID as below. 2014-01-23 15:50:41,724 [catalina-exec-35] INFO TRANSACTION getConnection ...
0
votes
1answer
51 views

Debian one time setup after reboot

I have a pre-configured server based on Debian with some services. I, now, need to deploy it in different networks. Is there any solution to run a one time script after reboot which asks some ...
3
votes
2answers
122 views

Bash Script To Find Debian Release Number from /etc/debian_version

The following is what I'm currently using for testing the version of Debian. Instead of doing it this way, can I make it more succinct? #!/bin/bash VERSION=NONE if [ $(cat /etc/debian_version) == ...
3
votes
3answers
329 views

Bash script to delete a file called index.html recursively

I need a bash script (not sure how to write the actual .sh file) which I could set to be run by cron every minute and that would delete files with the name index.html that are in a specific directory ...
0
votes
1answer
39 views

Prepare a computer for being firstly used in my home network with a BASH script is possible?

I need a script that detects the computer joined the same home network and standardize its folder structure. For example If there's A, B and C computers in a network which are configured to have a ...
1
vote
1answer
43 views

Does cron impose some limitations to types of commands and privilege of execution? [duplicate]

I've experienced an issue where some of my scripts run perfectly fine when I call them manually, but these same scripts when called as cron jobs via cron don't seem to work at all. So my question: ...
5
votes
2answers
163 views

Is it possible to execute a script as first at shutdown/reboot on Debian?

I am currently trying to register a script (located in the /etc/init.d) in a way that makes this script being executed as the first script/programm at shutdown/reboot (change to running level 0 or 6). ...
1
vote
2answers
109 views

Using a variable in a regex

How can I use a variable string in a regular expressions while read line do if [[ line =~ *"$key"* ]]; then echo line fi done < "$filename" $key is a string ...
-1
votes
1answer
74 views

How to use variables in sed

I want to print out the lines of a file between two indices in a Bash script. I have the file name and indices as variables I tried doing this sed -n "$2,$3p" $1 sed: -e expression #1, char 4: ...
0
votes
1answer
25 views

How to create an alias for opening a directory on Mac

Trying to create an alias hello. After typing hello in Terminal, then vi opens hello_folder. Now, this code returns: $ hello -bash: hello: command not found 1 #!/bin/bash 2 cd ~/Documents/ ...