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

learn more… | top users | synonyms (2)

0
votes
1answer
61 views

mv not working in script, but works fine on the commandline

I am trying to put together a simple script that renames a few files and directories. If I type the entries directly on the commandline they work fine. But as soon as I put them in a script it doesnt ...
3
votes
2answers
142 views

SED challenge,aggregating String containing braces

I've been trying to use sed for aggregating a specific string pattern within a text for hours, but can't find the solution. I hope you guys know how to do it!? The text subject to my Goal consists ...
7
votes
3answers
664 views

How can I safely ensure a variable contains only a valid filename?

Given the script below, how can I ensure that the argument only contains a valid filename within /home/charlesingalls/ and not a path (../home/carolineingalls/) or wildcard, etc? I only want the ...
2
votes
1answer
41 views

Script to multiple number fields

I have a large file with loads of different text. I want to use a script that will go through the whole file and multiple the number by a predetermined amount, in this example 2 in the EXP="XYZ" ...
0
votes
0answers
16 views

print out anything in between “function $argument” to “}”, where $argument is the function name, of a given file [duplicate]

Let's say, i have some functions defined inside my ~/.zshrc function foo() { # do some stuff } function bar() { # do # lots # of # stuff } I search basically for a way to ...
1
vote
2answers
43 views

How to run a bash script from a sh(dash) script?

I have a sh (shebang #!/bin/sh) script (sh.sh) which invokes a bash (shebang #!/bin/bash) sub-script: . "some-path/bash.sh" In the bash script I have a declaration of an associative array: declare -...
3
votes
3answers
111 views

How to read a properties file into an associative array?

I'd like to read the properties in a properties file into an associative array. How can I do it? Specifics on what to parse: hash and equal signs. Everything else is a bonus. Properties file content ...
5
votes
4answers
482 views

How to check if any IP address is present in a file using shell scripting?

I have a script that generates some output. I want to check that output for any IP address like 159.143.23.12 134.12.178.131 124.143.12.132 if (IPs are found in <file>) then // bunch of ...
0
votes
0answers
13 views

My tcsh say “Unmatched” or “No directory or file found”

I have .csh script. When I want to execute it with source 8.csh Some times it says, no directory or file found some times it says unmatched. I realized another problem too. I can see 8.csh in ...
3
votes
1answer
39 views

Ordered by insertion Map in bash

Is there an ordered (by insertion) map in bash? I know there's an associative array data structure in bash, but when iterating over it, the order of the elements is not by insertion. Example below. ...
1
vote
1answer
34 views

Put console on ttyS0 if guest OS is booted headlessly

We're using Debian 4 (No systemd) for our product. I run it as a guest OS managed by VirtualBox for testing purposes. Here's how I use it: For manual debugging, I have the guest OS's console on ...
1
vote
0answers
13 views

Modification of the sql loader control file [migrated]

I am working on a script which uses the sql loader to load data into a table . However , anywhere I search about the control file of an sql loader I am seeing only statements like "load data into ...
2
votes
2answers
72 views

how to send integer as a parameter [closed]

I need to write a script in Linux. I want to execute a function several times with a different parameter in each iteration. I write the following code: #!/bin/bash bash << _EOF_ for ((i=0; i&...
0
votes
0answers
27 views

executing shell script from launcher, slow to end/complete the script

I am using a bash script to rotate my screen via xrandr. To make it easier to use I added the script to the unity launcher. The problem I have encountered with this is that the script seems to ...
2
votes
2answers
89 views

Rename multiple files via shell script

I want to rename the following files 0 , 0.001 ,0.002 , 0.003 ... , 0.035 into 0 , 1 , 2 , 3 ... , 35 How can I do it?
2
votes
1answer
65 views

Shell: mutual piping of STDIN/STDOUT of two commands [duplicate]

When we run this with a POSIX shell, $ cmd0 | cmd1 STDOUT of cmd0 is piped to STDIN of cmd1. Q: On top of this, how can I also pipe STDOUT of cmd1 to STDIN of cmd0? Is it mandatory to use ...
3
votes
3answers
151 views

Could not execute a Bash Script if / while

I would like if someone points out mistakes in my script. The source where I'm learning from is so buggy that's why it's confusing me. PURPOSE OF THIS SCRIPT: It will count the numbers from ...
4
votes
3answers
188 views

Shell script: “if file is not being used” condition

I'm trying to compress a virtual machine image file through a script, but I want to be sure the file isn't being accessed. I could check if virt-manager is running, since it should be the only program ...
-1
votes
1answer
51 views

How to combine two files by shifting the value of the row file to its corresponding value in the column file?

I have a two files, the first has one row while the second with one column I would like to combine the two files by shifting each value in the row file to the same value in the column file, then ...
-3
votes
0answers
36 views

Outer loop stops without reading all lines of files when inside loop finishes in a nested while loop [closed]

I'm trying to use the below script to repeat actions to each line of the FILE. Inside the read while loop, I use another while loop to control the SYSTEM_COUNTER not to exceed MAX so that the system ...
2
votes
4answers
65 views

Redirect script stderr & stdout to a file, but keep stdout to tty as well?

In my script, I currently have: exec > >(tee -a /tmp/history.log) 2>&1 This writes both the stderr and stdout of all commands to both the log file and the tty. Unfortunately, this ...
0
votes
0answers
38 views

Mixing command substitution and extended globbing [closed]

The output below is admittedly artificial, but it illustrates the problem. To which paren is this error referring? syntax error near unexpected token `(' $ cat variables -a "a b c" -b "d e f" ...
0
votes
2answers
37 views

How to call script which is having menus, from another script

I have a script called operation.sh and while i am running the script, will be getting output like below and will wait for user input. 1. Start 2. Restart 3. Stop 4. Status Enter Option: Once ...
1
vote
1answer
37 views

Output in variable shouldn't be interpreted as command [duplicate]

So this question was asked some times already, but the answers didn't seem to work for me. So I have this simple script #!/bin/bash charon_id = $(pidof charon) kill -1 $charon_id And console says ...
6
votes
1answer
267 views

Check if variable equals open parenthesis

I'm currently trying to figure this out. if [ $CHAR == ( ] Obviously, this doesn't work. So how do I force it to do what I obviously intended? (For bonus points, how do I get the comparison to ...
1
vote
2answers
74 views

Timestamp not getting updated

I've written a piece of code but time stamp is not getting updated. It displays the time when the script runs and keep on displaying the same time even when loop is running and time is getting changed....
6
votes
1answer
88 views

How does sudo work (besides setuid)?

sudo is elevated to root upon launch because it's binary has a setuid enabled. But when I give /bin/login the exact privileges sudo has, and I try to run it from a user that isn't root, I get the ...
0
votes
1answer
40 views

Is there a function in shell script equivalent a var_dump(PHP)

I am beginner and I have a doubt in shell script. I'm doing some examples following this tutorials as: and I was curious to know if there is this kind of function in shell (var_dump PHP) because I ...
-3
votes
2answers
49 views

Bash scripting using #1 & #2 params but if files not found reverting to read from user [closed]

So if my user types in bash copy.sh copysource.txt copydest.txt - and the files are valid I want copysource to append to copydest and then show the file via cat -if the files names are NOT correct or ...
0
votes
1answer
24 views

Transferring a variable from one file to another

I have two files, config and template, and I want replace parts of the template with variables from config: config.txt contains: MYURL='www.google.com' template.txt contains: url = MYURL I used ...
1
vote
2answers
55 views

How to use exit status in crontab

I add the following script line to the red-hat crontab, script should run on Saturday in 5:00 in the morning. In order to run the script /var/scripts/PLW.pl every Saturday at 05:00 morning. I want to ...
1
vote
2answers
38 views

How to execute script located in the same directory as current script?

Why shell scripts are so hard to develop? In NodeJS I could simply do: require('./script') and it will always require script relative to current script. But if I try that in shell/bash: ./script....
1
vote
1answer
33 views

Assign continuous stream to variable and process the variable

I'm trying to make an analyzer for a custom log that I have. My log file has a duration timestamp (in ms) which I want to filter out from the others and send me the logs that take over a threshold ...
2
votes
2answers
256 views

How to count values that match a certain condition?

I have file with number of columns for example input file 12 15 27 5 6 48 19 16 25 17 23 37 etc I want to count all the numbers (X) in column 2 for example that fulfill the ...
2
votes
1answer
26 views

UDEV Rules Interfere

I am working on Raspian OS (Linux) for Raspberry Pi 3. I am trying to do a simple task say when I connect any USB to the port it should copy the data from a particular location to the USB and clear ...
0
votes
1answer
26 views

Execute script in new tab command line gnome-terminal

Hello i want to open a new terminal and execute a script immediately to it (to set a title in the new tab) and i cannot configure this. I try: gnome-terminal --tab-with-profile=$varname -x ./test.sh -...
1
vote
2answers
31 views

Install the content of a folder into another

I'm trying to write a Makefile to install the content of my folder into another on the system. I would like to keep the same directory structure, like this. localfolder ├── a └── b ├── c    ...
-1
votes
2answers
34 views

Privilegies of command inside shell script

I need to run simple script to check host status (ping), I have following script: #!/bin/bash echo "Host checker:" if [ "`ping -c 1 172.17.10.1`" ] then echo "HOST UP" else echo "HOST DOWN" fi ...
-2
votes
2answers
44 views

Insert a character at a specific location in ksh

My input is LOAD_DATE = 20072016 I want the output as LOAD_DATE = 20-07-2016 This is sample date. Date will come through LOG_DATE=echo ${LOG_FILE_NAME} |cut -d"." -f3 Sample dates "20072016,19072016,...
0
votes
0answers
16 views

Shell script output used as an sql script [duplicate]

Suppose I am using the following script #!/bin/bash PREFIX="A2B1 " TABLE="sqltablename" COLUMN="sqlcolumnname" if [[ ! -r "$1" ]]; then echo "unable to read file '$1'" exit 1 fi cut -d, -...
-4
votes
0answers
22 views

Taking the value of a particular column from each line and updating a table in a sql db

My csv file students.csv contains records in the following format : (student name , college ID , Roll no ) I have a table named "student" in my database having records in the same format .What I ...
1
vote
2answers
73 views

A script to take data from csv file and perform related operations in a database

I am new to the world of shell scripting and don't have much idea of shell scripting . My work requires me to write a script which takes phone numbers from a list of records stored in an CSV file . ...
-2
votes
1answer
27 views

add two numbers in bash script [closed]

Noob here. I was trying to add 2 numbers from command line and I can't figure out why I am getting the output as 0. #!/bin/bash args=("$@") if [ ${args[0]} -eq ${args[1]} ] then echo "The sum ...
0
votes
1answer
19 views

Running a series of scripts in MySQL

I have files named like: File1_01.sql File1_02.sql File2_01.sql File2_02.sql I need to run all the scripts for File1 first (but these can be done in parallel), then all the scripts for File2. What'...
1
vote
5answers
91 views

Killing a named process older than X minutes? (no killall -o)

Okay, first post! So I have this situation where I need to check for a process older than 5 minutes by a particular process name. The problem is that the system in question is a customized version of ...
0
votes
0answers
52 views

copying a file via a linux bash script: seemingly not working

Below is a simple script I have written to collect data contents of files from different directories named dyn1, dyn2, dyn3 ... dyn15. I will add more to the array list (other file names) but for now ...
6
votes
7answers
349 views

How to secure a sudo - powered script

Solution for executing root commands as unprivileged user - sudo 'ing script - easily opens possibility of security breach and unexpected behavior and results (this is also true for any other solution ...
0
votes
1answer
27 views

Move selected information form one TXT file to ANOTHER

I have two txt files: config.txt and template.txt template.txt has to take relevant information from config.txt Let's say config.txt contains: colour1: red colour2: blue And template.txt contains:...
0
votes
1answer
27 views

Linux redhat crontab + run script with arguments

I add the following line to the red-hat crontab in order to run the script /var/scripts/info_from_all_sites.bash every Friday at 00:00 night script should get as argument the file - /var/RT/names....
2
votes
2answers
29 views

finding a folder names based on list contained in .txt file

I have a .txt file containing 150 different ID number on each line like so: 12345 15876 19643 12586 Located in the same directory as the .txt file, I have 300 folders and I want to copy only the ...