Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [shell-script]

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

1
vote
1answer
21 views

Why isn't svn using my credentials when run within a shell script?

I have a collection of a dozen directories which are all separate working copies of different svn repos. They are configured the same way on all my machines so I can work on any of them at any time. I'...
1
vote
1answer
41 views

Shell script : add “exit by typing q” to while do case already dependent on an if

I'm writing a shell script : #!/bin/bash i=1; sp="/-\|"; no_config=true; echo "type \"continue\" to exit this while loop"; echo "if you feel the conditions for continuing sucessfully have been met......
1
vote
1answer
25 views

How add new lines between rows and start and end position of the csv file

The below input data contains table attribures with header information. The expected output is given below as well where the header and newline with intended text. This is expected as and when there ...
0
votes
0answers
23 views

Why shell script function can't return negative number? [duplicate]

When I use shell script , function can't return negative number. Why is that please?
0
votes
3answers
58 views

How to make code interpret $ but not *?

I have some perl code (don't focus on what it does right now, i'm still working on it): #!/usr/bin/perl -w if(!@ARGV) { print ("ERROR: NO ARGS\n"); exit 1; } else { use Cwd qw(cwd); my $dir ...
0
votes
2answers
38 views

adding contents with multiple files using awk, sed or grep

I have to files named file 1 and filed 2 following format: file 1 with 18000 lines COL1 COL2 COL3 COL4 COL5 - . ID = tom_fa_10005086 - 0 Parent = tom_fa_10005086 - 0 Parent = ...
0
votes
2answers
33 views

Renaming files with the same name when moving them

This is my current code: Base_DIR=/file/path other= /folder/path find "Base_DIR" -type f -name "*.txt" while IFS= read -r file; do year="$(date -d "$(stat -c %y "$file")" +%Y month="$(date -d "$(stat ...
0
votes
1answer
26 views

Rename Root folder directory - I've managed to rename folder structure to my name by mistake

Using Kali Linux and somehow managed to rename a folder in the structure: root:/bin/bash/myName So my question is how can I rename the myName folder? as I would like to set up a new user profile ...
0
votes
1answer
17 views

Parsing folder structure with $HOME in the name

So I am a making a simple backup script, it will be run every hour. All this script does, is make a backup directory and copy files: ./backup/'$HOME'/Documents/todo.txt backup structure - backup ...
0
votes
1answer
35 views

Looping through two files with a for loop and evaluating the indices

I am learning bash shell scripting and am looking for pure bash ways rather than awk, etc. I am trying to use a for loop to go through the contents of two files that are submitted as arguments in the ...
2
votes
2answers
28 views

JQ Linux JSON Parse Unknown Key

I want to build an automated script which builds an new VPS Server on the page vultr.com. They also have an API Access and I could create it and receive also anything I need. The problem is, vultr ...
0
votes
0answers
8 views

Why is this Thunar Custom Actions Pastebin script posting with unwanted quotes?

This question is regarding these nice thunar custom actions scripts which I found here: https://github.com/cytopia/thunar-custom-actions One in particular is doing something strange that I can't seem ...
5
votes
1answer
193 views

Unix AIX passing variable and arguments to expect and spawn

I am writing a script to scp some files but need to pass file location through the user or another script as an argument #!/usr/bin/expect set FILEPATH1 $1 spawn sh "scp $FILEPATH1 $USER@$HOST:/...
1
vote
1answer
54 views

writing a script that finds incorrect files, and corrects them through stdout

I am currently using UNIX bash, and I want to write shell script that allows me to correct the date entry by using information in a file's pathname. Background: I previously had 200 files that were ...
0
votes
2answers
22 views

How to save a query result in a variable?

Consider table1 has 15 records. I need to find the count using the query 'select count(*) from table1' in the shell script. The result should be saved in a variable 'S1'. So when I am viewing, the ...
0
votes
3answers
38 views

Combining multiple columns and insert information in middle

I have to 3 files with all containing columns of information id.file 1 2 3 name.file Josh Kate Chris lastname.file Smith Jones Black And I would like to combine them in a way, so I can get ...
2
votes
1answer
149 views

Bash script to execute command with file from directory and condition

I'd like to sort my figlet fonts with testing, so I've decided to make a script, which will demonstrate figlet font one by one and will delete fonts I don't like. I've tried to find the solution for ...
0
votes
3answers
27 views

remove specific characters from a string

I need to replace spaces with comma and then remove certain extra specific chars from a string. echo "$d" >>Mon Apr 22 05:06:00 UTC 2019 jent=$(echo $jt1 | sed 's/[[:space:]]/,/g') echo "$jent" ...
1
vote
2answers
39 views

grep from list of keywords

Over the past couple of days I've been trying to dig through directories of files to report on files containing key words. Through the help of other users showing me the correct syntax for grep and ...
-1
votes
0answers
17 views

How can I check if a file is available on SFTP?

I'm writing a script where it should connect the remote host and then, connects to sftp and list the current day file I got to a certain point with what i wrote: #!/bin/bash key="keys/prod_key" date=...
0
votes
1answer
30 views

Why my script is not working? [duplicate]

Hello I am trying to move a group of directories with the mv command and curly braces expansion as follows: #!/bin/bash ... group_name=$1 group=$((total/set)) group=$((group-1)) mkdir "$group_name""...
0
votes
0answers
10 views

How to validate pbrun working or not but not really doing pbrun

I am developing and health check script for our application and we need to validate few things after every major change and/or patching . One of the checks is whether the pbrun access is working or ...
-1
votes
2answers
30 views

Swapping the contents of two columns

I am trying to understand cut better and moving cut data to another file. I have a file called numbers with two columns. Each column is separated with one tab. I am trying to swap the columns by ...
0
votes
1answer
14 views

Open a tmux session and then change to different user without password prompt

I am trying to create a script that opens a new tmux session and then runs a command inside that tmux session as a different user. The purpose of this is to create a new tmux session for a game ...
-2
votes
3answers
96 views

How to make commands like : sudo or read [on hold]

I am trying to make a sudo-like/read-like command (To just see what happens, also for roleplay) so I made my bin directory (Because I am using Linux on a Chromebook) then I made a atc folder (that is ...
1
vote
1answer
41 views

Confused about determining if a shell script is running interactively

I only want to determine from my POSIX shell script, if it is running interactively, but for some reason, the following function: running_interactively() { printf '%s' ${-} | grep -F i > /dev/...
0
votes
1answer
33 views

sed command working only when no outfile is written

I'd like to change this file eq.txt 2018-05-03T18:46:05.050Z 11.8314 44.0586 10 4.3 USGS 2018-05-01T05:16:59.270Z 11.0366 43.2334 10 4.1 USGS 2018-04-26T11:13:20.590Z -5.4109 36.5557 10 4 USGS 2018-...
0
votes
2answers
67 views

Grep in file with whole cat output

I search/try to write short script (for if loop) to do grep in file by whole cat output. Already I tried #!/bin/bash find -name 'xmlrpc.php' -execdir bash -c ' if [ -e ".htaccess" ] ; then if grep -...
0
votes
0answers
14 views

On Ubuntu Server latest LTS on Digital Ocean how can I automatically detect github commits? [closed]

I have a git repo on windows, say I am coding an html page, index.html or whatever. I save this in my git repo locally on windows, then I commit to at github.com/myusername/myrepo to say the master ...
-1
votes
3answers
85 views

How to make a password in script [on hold]

I am working on a terminal-based program and thinking there should be a password (That I would specify if I upload or make the user create one, I have tried #!/bin/bash PS3='Are you sure you want ...
0
votes
0answers
25 views

sed Shell Script not working correctly

I have this shell script that is supposed to go through a file and replace its primitive types with other specific text (it's for an assignment). The script is below: #!/bin/bash #Goes through an ...
0
votes
1answer
33 views

How to input a digit into files created from a loop?

This is the original problem: Create a script fivedirs that does these tasks: make a directory five make five subdirectories five/dir1 through five/dir5 in each subdirectory, make four files, ...
-1
votes
0answers
30 views

How to do operation math with number words shell script?

I want to read a file and inside the file have number words. I have to do operation math. but I dont know why my script doesn't work. Exemple : seven one minus six one the answer in the terminal : ...
0
votes
1answer
26 views

compare a certain number of lines between columns of two files

I have a thousand files and I need to verify if they all have exactly the same information in the second column up to a certain number of lines. Below an example. I would like to print the names of ...
0
votes
1answer
22 views

Reading an argument and creating a tempfile from it to use within the script

I am trying to write a script that would count the number of columns in a file. However, I don't know what the name of the file will be. I am trying to create a file called tempfile which has the ...
-1
votes
1answer
22 views

How to append * to the String and assigning a prepared SQL Query to another variable? i.e., (select * from …)

I'm trying to create a SQL Query and trying to assign it to some variable but I couldn't do that. TABLENAME=foo QUERY="select * from $TABLENAME" echo $QUERY I'm expecting the Query would be select * ...
1
vote
1answer
20 views

korn shell - if a variable exists in an array stop processing without exiting

How would one evaluate priority of items in an array such that you only process the highest priority item that exists? Let me try to explain, if I had an array set -A array low medium none high ...
1
vote
1answer
22 views

Commands Not Found when Passed through SSH

System: Red Hat Enterprise Linux Server release 7.6 (Maipo), 3.10.0-957.el7.x86_64 GOAL: Collect configurations for data from multiple servers to validate they are the same. What Works: ssh $...
0
votes
1answer
48 views

Why can't I execute .bashrc directly and what is “sourcing”?

My .bashrc has the following permissions: -rwxr-xr-x So it's labeled "executable". My newbie brain tells me I should therefore be able to just run it. But when I try $ ./.bashrc I get: ./.bashrc:...
-1
votes
0answers
13 views

Dynamic Log Remove

I want to delete logs in Linux machines and the path example below. /test1/test2/test3/x/a/b /test1/test2/test3/y/a/b /test1/test2/test3/z/a/b Thing is directory changes after the "test3" folder I ...
-3
votes
1answer
38 views

Script program for checking IP connectivity [closed]

I need a program to check the IP connectivity. Like I will be having more than 100 different IP addresses. For each IP address, I need to check whether it has connectivity or not. My challenge is I ...
1
vote
1answer
21 views

Starting wpa_supplicant via script in systemd not working properly

I've written a script to manually start the wpa_supplicant function on a Fedora/Centos7 machine with a wireless NIC. Due to static routing issues, I cannot use NetworkManager (nor do I want do with ...
0
votes
1answer
25 views

Bash String manipulation when string contains parentheses

I have a directory full of files with the name template xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip The zip files contain a file yrq000.dat and I don't want to overwrite them when the files are ...
0
votes
1answer
46 views

Understanding grep -oP … In a script

I'm writting a litlle bash script for debian. I want to find the 3th octet of my IPv4 and push it into "ip1" variable, and push the final octet in "ip2" variable. After some researches I found a ...
0
votes
1answer
40 views

bash: syntax error near unexpected token `;'

I got this error bash: syntax error near unexpected token; while running this line: while; do; clear; tree .git; sleep 1; done I got this line from this video
1
vote
2answers
58 views

fastest way to subsitute on 10GB file for multiple expressions

I have a file of 10GB data, I want to execute 2048 substitution expressions of sed -i 's/pattern/replace_pattern/g' on that file. Is there a way to do it faster and effectively. Currently, I am ...
1
vote
1answer
22 views

How to Merge Multiple Columns in to Two Columns based on Column 1 Value?

I have a text file in the below sample format File.txt Record1 20 23; Record2 256; Record3 45 679 98 1; The no of columns in each line can vary. I want to change the file with only two columns ...
0
votes
1answer
28 views

Use bash EXIT trap to confirm or cancel ctrl+d [duplicate]

Is there a simple way to require confirmation before logging out of a shell, and to prevent the shell from exiting if confirmation is denied? This would be useful to avoid accidentally terminating an ...
1
vote
1answer
37 views

Unable to find regular file with default shell as bash but works when it's ksh

We have script file FileChecker.sh where it checks whether file exists or not FileChecker.sh content: #!/bin/ksh FILE=$1 FILE2=$2 if [[ "$FILE" == "" || "$FILE2" == "" ]] ; then echo "[ERROR] ...
0
votes
2answers
24 views

How to delete columns with zero value in each line?

I have a file containing numeric data. Each line has a varying number of columns. In each line, I want to delete the columns containing 0. Below is a sample Input 25 60 0 29 0 10 23 0 26 43 49 1 56 ...