Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

0
votes
0answers
15 views

Shell Script basics for validating user credentials

Shell script that validates username and password. Checks the values if the data does not match.it should alert and again prompt for correct username and password instead of coming out to the terminal ...
0
votes
0answers
8 views

Repeat on user press, open up terminal, close terminal?

I am making a program and would like it to loop if an user presses a key. I also want to know if the bash file can automatically open a command terminal if it is not running from one to achieve the ...
0
votes
0answers
8 views

Print Windows mapping of root path in MSYS Bash

In MSYS Bash I get: $ cd ~ $ pwd /c/Users/antonio but: $ cd / $ pwd / Can I get the full Windows absolute path from Bash?
5
votes
5answers
923 views

How to move all sibling folders into one folder?

I apologize that this seems like such a dumb question, but I can't afford to screw it up. I have a bunch of folders like so: /users/me/foo/oops1 /users/me/foo/oops2 ...
8
votes
4answers
5k views

How to truncate file by lines?

I have a large number of file, some of which are very long. I would like to truncate them to a certain size if they are larger by removing the end of the file. But I only want to remove whole lines. ...
1
vote
1answer
15 views

Directory auto completion in bash scripts

Bash scripting newbie here writing my first script to copy a directory of pictures from one place to another. #!/bin/bash # Moves picture directories cp -R /path/to/pictures/$1 ...
3
votes
2answers
27 views

How to work around Bash for loop not exiting when a subcommand errors?

I have a for-loop in a shell script a la: #!/bin/bash set -u set -e for l in sh rb py php java cs; do (cd $l; ./run-tests.sh) done The intent is to have the for-loop die in a fire when any one of ...
1
vote
1answer
4k 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 ...
0
votes
2answers
33 views

using 'case $1 in' to read command options- multiple flags after dash, and handling unusual flags?

I am making a bash script which uses both long options and short flags. Since I want long options, I can't use getopts. I tried using the following code: while test -n "$1"; do case "$1" in ...
0
votes
1answer
26 views

Script not working when run automatically

This script (parts of it) runs perfectly when invoked manually from the Terminal: #!/bin/bash [[ "`ps -e | grep -c $(basename $0)`" -gt "2" ]] && echo -e "`basename $0`: Mutiple instances ...
0
votes
1answer
23 views

Calling a list of functions provided on a stream

I'm writing a bash script to configure a server in which the end user will have to choose the actions to perform and the script will execute them. Each action will be implemented as a function. I've ...
0
votes
2answers
87 views

Getting errors trying to run shell script (Linux)

I'm trying to run the following script. I have run it before without issue, but now I encounter an error. #!/bin/bash # init function pause(){ read -p "$*" } echo & echo "(Website):" ...
1
vote
1answer
43 views

How to make variables used in read global for the script

I want to read a file with the data ordered in column. In the script that I'm writing I use the read command. The input file is made by lines like the following: XX:XX:XX:XX:XX PQRTS ...
0
votes
1answer
115 views

How do I run multiple scripts within a script, even if one script fails

I have a simple bash script that executes a number of other scripts … #/bin/bash … ./update_artifact1.sh $ARTIFACT_VERSION ./update_artifact2.sh $ARTIFACT_VERSION ./update_artifact3.sh ...
0
votes
1answer
35 views

pass filename(with space in the path) as argumant to a wine app in a bash script

I want to luanch an wine App with passing a file as argument. I've two file, with the first I don't have any problem but when there is a space in the path wine can't handle the address properly. here ...
8
votes
4answers
5k 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?
0
votes
1answer
23 views

Renaming files in a folder (and subfolders) by removing a token in filename

I have a huge amount of files in a folder (and subfolders) that I need to rename. For example, I have: movie1.mp4 fixed_movie1.mp4 ... What I need is to rename fixed_movie1.mp4 to movie1.mp4 ...
1
vote
1answer
88 views

Linux Bash “|” operator doesn't work - what am I doing wrong?

I am trying to check user password via login command like this: # echo "name\npassword" | login but the command ends without writing anything. echo ends because of SIGPIPE. Why did login stop ...
0
votes
1answer
15 views

Backing up github [closed]

I have a bunch of github directories and have been using a script with the "cp" command to backup to an external USB drive. I was wondering if I should be backing up directories that I make for ...
0
votes
2answers
85 views

Properly escaping forward slash in bash script for usage with sed

I'm trying to determine the size of the files that would be newly copied when syncing two folders by running rsync in dry mode and then summing up the sizes of the files listed in the output of rsync. ...
1
vote
1answer
48 views

Unable to delete a file using bash script

I'm having problems removing a file in a bash script. I saw the other post with the same problem but none of those solutions solved my problem. The bash script is an OP5 surveillance check and it ...
0
votes
2answers
2k views

FTP from bash script running from cron not working

I have a script that is run by cron to create backup of a MySQL database and some files. After creating a tar ball and encrypting it with openSSH I have to put it on a remote ftp server. Following is ...
0
votes
1answer
71 views

Simple script run via cronjob doesn't work but works from shell

I am on shared hosting and I'm trying to schedule cronjob to run every now and then. Via cPanel I scheduled to execute my script but even though that according to my host support the cronjob runs, the ...
9
votes
3answers
7k 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
3answers
66 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 ...
2
votes
1answer
31 views

Are shebang invocations detectable?

Is there a way for a bash script to detect if it's being run via the #!/usr/bin/env shebang? Some magic bash foo that would let me write: #!/bin/bash ... if [ __INVOKED_VIA_USR_BIN_ENV__ ]; then ...
0
votes
1answer
64 views

Execute the shell command in subshell or in background?

Actually I mainly work with Ruby, but now I have created a bash script file. From this script file I am displaying the messages on the screen. Here is my scenario. I have used aosd_cat module for ...
0
votes
2answers
44 views

Script variables not printing as expected

In an attempt to debug a script, I'm printing variables containing text, pretty standard stuff, except that the variables are not behaving as expected. I've discovered that one of the lines of a file ...
1
vote
2answers
37 views

How do I print multiple sections in a text file?

I have a text file looking something like this: *FILESTART line_a line_b line_c *INCLUDE file_A.key file_B.key *INCLUDE file_1.key file_2.key file_3.key *SOMETHING_ELSE line_x line_y line_z *END I ...
1
vote
1answer
32 views

I am not sure what type of quotes to use in a bash script

I am working on a script. I am having it call a program that has an input directory. The program looks like this if executing it from command line /path/to/program -c /path/to/config -d ...
0
votes
1answer
25 views

Text file sort. Ignore rubbish and create .csv from remnants

I've got a load of files containing preamble rubbish followed by formatted information. They're all the same format. I want to ignore the preamble, (everything up to and including the word ...
1
vote
2answers
47 views

How do i run su username -c “command ” in a sequence

am trying to write a script that runs commands in a sequence as a user but su keeps doing every command at the same time instead of running them one after another the script looks like su username ...
0
votes
0answers
47 views

Autoexport bash internal variables

I need to access to some bash internal variables (BASH_LINENO, BASH_SOURCE) from a command invoked by a shell script. The only possible interface between my command and the script are environment ...
1
vote
1answer
116 views

HandbrakeCLI bash batch script not working.

I am trying to batch encode a bunch of files. Looking over the internet I have found just a couple scripts and none of them worked for me. I started to piece together something and it is close to ...
2
votes
1answer
24 views

Can you delete all users but specified accounts in Ubuntu?

I am trying to find a way to quickly delete all user accounts except for the ones I specify in Ubuntu. Is there a good way of doing this? Perhaps a bash script that could do this function? I ...
1
vote
1answer
31 views

Move Files having No Extension

I have 5 files in a directory log.txt abc.pdf def.ppt 1CC 1DD Now I want to Move files having no extension i.e 1CC and 1DD to a another directory i.e tree. whenever i am manually using command it ...
1
vote
1answer
45 views

Find last 24 hours executed commands per each user in bash

How can I find last 24 hours executed commands per each user and mail them the result? I have Ubuntu GNU/Linux. I find out that I need a package named 'acct'. I have already installed and enabled that ...
0
votes
0answers
27 views

Combining a bunch of find commands into one command or script.

I was wondering how to combine a bunch of find commands into one. This is the list of find commands I want to run and in the order. find /path/to/folder/ -name '*Sample*' -exec rm -rf {} \; find ...
1
vote
1answer
38 views

How to recursively create a directory if it does NOT yet exist?

This seems like a general utility and am wondering if anything already exists. I'm trying to place a timestamped logfile in a directory after a script runs, but need to make sure the subdirectory ...
1
vote
1answer
11 views

How do I suppress the terminal window when I launch a bash script from Spotlight?

When I run a bash script from Spotlight, a terminal window launches to execute it. The window closes when the script finishes but I'd like to prevent that window from appearing on my desktop at all. ...
0
votes
1answer
28 views

grep and search and replace in linux accepting parameters with /

I'm trying to find and replace the contents of a file using grep and sed. ```grep "#!/bin/bash" ./ | sed xargs -i 's/#!/bin/bash/#!/usr/env bash' How do I make sure that the string #!/bin/bash will ...
0
votes
1answer
109 views

Bind bash script to keypress

How do I map a keypress on a keyboard to a bash script? For example, when I press the "Esc" key, the script is run. OS: XFCE Spin Fedora 19 ---- EDIT ---- I need to set this via the console. This ...
1
vote
0answers
125 views

IDE for Bash shell scripting on Ubuntu? [closed]

I'm probably looking for the Holy Grail here, but I figured I'd ask. Is there an IDE for Bash shell scripting on Ubuntu (Ubuntu 12.04 in my case)? Something with a code editor that lets you set ...
1
vote
1answer
47 views

How to run a bash script in a daily basis on my remote server?

I have code need to be run in daily basis at my ubuntu remote server. How can I set it to go as described? Is there any console too to help me ? And this code should be activated itself as the machine ...
1
vote
1answer
36 views

Trim File Names of Tarballs Using Bash

I need to grade some source code from various students. The submission process is through Blackboard which appends to the file name a bunch of unnecessary stuff. Here is an example: Test ...
0
votes
1answer
39 views

find files older than create its parent folder in a directory and move them there

I've been trying to create a bash script that does the following. Use the find command to search for files older than 7 days (find . -type f -mtime +7 ! -iname '.*', take the parent directory(of the ...
1
vote
1answer
232 views

qsub -hold_jid -afterok loop not starting

I am trying to run a series of jobs submitted to the cluster, one after the other, by suplpying the following .sh script: Annotation_Loop.sh : #!/bin/bash job=`qsub run_IntersectBed_1.sh 0` for i ...
0
votes
3answers
113 views

“cp --parents” equivalent on Mac

The topic explains it -- basically I have a bash script used on a Linux system and a Windows system with Cygwin where the following command works perfectly: cp --parents However, running this same ...
0
votes
1answer
23 views

How do I extract multiple files at once?

I have a number of rar files stored like so: /torrents/televisionshowS01E0$X/nameoftelevisionshow.rar where $X is a variable ={0,1,2,...,12} I would like to extract them using a single command to ...
0
votes
0answers
31 views

Vagrantfile - is rvm in ~/.rvm/scripts/rvm or ~/.rvm/bin/rvm?

I'm still learning my way around some of the more hidden files in terminal and I was trying to setup a Vagrant box with rails via shell script provisioning, with some help from these links: ...