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 [bash]

Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

0
votes
0answers
37 views

space isn't release after removal [duplicate]

I accidentally created millions of directory with my script. After I rm -rf them, there are still space occupied by my removed directories. Also there is about 2 seconds delay every time when my ls or ...
0
votes
1answer
27 views

how to use openssl random key in bash script?

Below is my sample code: KEY_FILE=/tmp/key.txt KEY=$(openssl rand 16) echo $KEY > $KEY_FILE ID=2345 source .mysqlCredentials.txt MySqlCommand="mysql -h $IP -u $UserName -p$Password $DBName -e" $...
0
votes
0answers
55 views

How to make a full bash script that compares the shadow and the passwd file?

I have two files, passwd and shadow a. Sort both files b. Compare both files line by line   i. Match on user name output to third file   ii. If it doesn’t match, output to fourth file   iii. ...
1
vote
1answer
51 views

Understanding bash outputs when backgrounded jobs are not found

When I enter the command: a&b I receive the output: [1] 15872 b: command not found a: command not found When I enter the command: a & c My terminal's output is: [2] ...
2
votes
1answer
52 views

Create persistent array in bash

I want an associative array in my bashrc file and I want to add to or delete from it whenever needed, but if I put the array declaration in the bashrc file it will get redeclared every time bash is ...
1
vote
1answer
26 views

How do I save image produced by asciiview?

When I run command asciiview image.jpg I'm able to view image in the terminal and quit browser using q key. I've tried different ways to redirect the output of the asciiview image.jpg to the console ...
-1
votes
1answer
20 views

access soft symlink directory's contents in bash [duplicate]

I have a bunch of symlinks pointing to various directories. Each of the target directories happen to have a space in them, I have not created them like that, but they are being received as such via ...
0
votes
0answers
35 views

Bash createfile in memory

I'm coding a script in bash to use in clonezilla live on hard disk. I place the main script in a directory that can be accesible in clonezilla, which can be edited from the host SO, mounting the ...
4
votes
1answer
233 views

Run script for 10 times or until it meets the condition

I have following shell script. OUTPUT=$(systemctl is-active etcd) if [[ $OUTPUT == active ]]; then echo "The result is successfull" else echo "The result is unsuccessfull" fi I ...
0
votes
1answer
20 views

Is there a simple way of determining which executable is being invoked by a given command when which is not available? [duplicate]

I am working in a linux system that does not have a which command. Is there an alternative way of finding out which executable is being run by a given command in bash? It is a super basic system (...
4
votes
2answers
244 views

Size of a folder with du

I have copied a folder using rsync including symlinks, hard links, permissions, deleting files on destination et cetera. They should be pretty identical. One folder is on a USB drive and the other on ...
-1
votes
1answer
24 views

How can I pass an argument in a shell script without quotes?

I have to make my own command shell where a bash script calls the shell executable and does so with quotes. The problem is that when I try to do so with logical operators it seems that the quotes turn ...
0
votes
1answer
25 views

How to compare user input with content in text file?

I am making a script that allows users to save their settings in a text file. If they want to use the saved settings, they will need to input the name of the settings. Then the script will compare the ...
0
votes
1answer
25 views

Evaluate command based on variable at bash [closed]

I am writing a small script that would choose random file for me from the directory and execute command with this chosen filename as a parameter. It is about choosing random .ovpn file and run sudo ...
0
votes
1answer
29 views

Bash not loading inputrc automatically

No matter what I try I can't get bash to load my ~/.inputrc file. The most minimal example I have tested is getting rid of my ~/.bashrc and then having a single line in my ~/.inputrc with set ...
0
votes
2answers
23 views

Using grep for the output of a command [duplicate]

grep might not be the solution to what I need. I'm trying to grab the MB/s info from this command dd if=/dev/zero of=tempfile bs=1M count=1024 which returns the following information 1024+0 records ...
0
votes
2answers
52 views

Copy every 10 files from source into a target directory using cp

I have 110 large files inside a directory. But I cannot copy them at once since the system gets timed out after 50 min. I want to copy files 1 to 10, next 11 to 20, next 21 to 30, and so on. The order ...
2
votes
1answer
33 views

Difference between Piping and Reading Input

What is the difference between cmd1 > tmp && cmd2 < tmp and cmd1 | cmd2, besides the creation of a tmp file (obviously) ? If my comprehension of pipe is right, I expect cmd2 to read ...
-1
votes
1answer
24 views

why does test command startswith fail (exit with 1)?

I have this test command: test "ssh://hg@bitbucket.org/teros/moodwire_demo" == ssh*; echo $? why does it exit with 1? I am trying to see if the first string starts with the second string.
0
votes
0answers
19 views

how can I split a string into indevidual characters in an array using bash? [duplicate]

basically, i just want to turn something like "hello world 1" into h e l l o w o r l d 1 so basically each character of the string, including spaces, is turned into a single element ...
0
votes
1answer
23 views

Fork urxvt in bash without hitting Control-c

I know I can create new sub-shells (please correct me on terminology) in bash by using &. However this requires me to hit Control-c to get back to bash with most programs. Is there a way to stop ...
3
votes
3answers
271 views

Remove everything except csv file Bash Script

I would like to delete everything from a folder except csv files I am trying with a bash script and I am getting this error: syntax error near unexpected token `(' This is my script : PATH=/tmp/ ...
0
votes
2answers
84 views

Bash needs to send a command to another CLI

I want to automate some command the thing is we login to the server and the next commandline isn't a linux commandline but rather that of an application it self. My current attempt of solution is the ...
2
votes
2answers
44 views

PIPESTATUS from commands in $(…|…)

How to read ${PIPESTATUS[0] of a command, when a variable is set in current shell? Is there a way to pass it to current shell somehow? I am setting variable MAIL=$(ldapsearch.... | find_for_mail) and ...
2
votes
1answer
27 views

Pass script to background using script itself

It is possible to do something like this: nohup ./run.sh > /dev/null 2>&1 & Which sends the process to background, discards its output and allows us to close terminal. Is there any ...
-2
votes
0answers
36 views

bash script with case statement conditions not getting executed [closed]

#!/bin/bash # This script is designed to check the size of the Splunk file system on all the Heavy Forwarders and purge the old data if the space is running out. # The HFList.txt file contains the ...
0
votes
2answers
43 views

How to move some specific folder keeping a predefined directory structure?

I have a directory containing about 7k folders. These folders were extracted from zips and some of the extraction was done using Python scripts. Some of these folders are extracted in such a way that ...
1
vote
1answer
20 views

If condition on shell not working , not sure what is the mistake I am doing? [duplicate]

I have a requirement to perform specific set of tasks based on server , So I want to have the condition(s) defined based on server. Here is the script I came up with and I have read multiple blogs and ...
1
vote
1answer
34 views

How to get the list of files in a directory

I try to create an array/list which stores file names inside a folder. The below command creates for unknown reasons a :. How is possible to remove :? > a=$(ls split*) > echo $a split_sam....
0
votes
0answers
26 views

Nesting back-ticked commands [duplicate]

I have this which won't work: source_dir=`cd `dirname `readlink "$BASH_SOURCE"`` && pwd`; what does work is this tho: source_dir=$(cd $(dirname $(readlink "$BASH_SOURCE")) && pwd); ...
-1
votes
1answer
28 views

Error EOF Syntax Error

-bash: /Users/tj/.bash_profile: line 17: syntax error: unexpected end of file This is currently at the top of my terminal window. I need to fix this error. I have deleted the last line out of my bash ...
1
vote
2answers
28 views

Non-Root User SSH Privileged Command with File Piping

I have an a SSH server where root login is disabled. I'm hoping to run a privileged command that will want input from a file I have after being executed. I'm hoping to do all without user interaction ...
0
votes
0answers
22 views

Why does single quotes around arguments fail to prevent “syntax error near unexpected token '('”? [duplicate]

I read that surrounding command line arguments with single quotes is necessary when the command line argument is a string that contains parentheses. However using single quotes around the following ...
1
vote
1answer
45 views

Automatically print number of lines of command line output

In my fish shell, I am using fish command timer to automatically show the duration of each command after it has been executed. This is a neat feature, which I recommend. Now I want something similar ...
0
votes
1answer
32 views

How to send stdin to while loop using redirection operator

Not sure if I used the right words in the title, I am trying to do this: while read line; do echo "$line" exit; done; <( echo "foo\n"; exit ) but it hangs, I don't think the while loop ...
0
votes
1answer
35 views

very long string variable?

Is there a longer type variable for building lengthy sql statements? how add new line too? I want to store the statement in a very long variable text so I can run it from sql prompt. I think it will ...
2
votes
4answers
94 views

Correctly quote array that is being passed indirectly via another command

I need to pass an array of filenames to a command, preserving proper quoting. So far, so good. Unfortunately the command is actually a sub-command that is, in turn, invoked by another command. ...
2
votes
1answer
30 views

Open output of a command using libreoffice

I am running certain commands in a loop and would like to open its output in libreoffice (calc), without storing it. This is what I have tried: libreoffice --calc <(process m n) libreoffice --...
2
votes
1answer
60 views

What is the most succinct way of terminating the rest of a pipeline if a command fails?

Consider the following: command1 | command2 | command3 As I understand pipelines every command is run regardless of any errors which may occur. When a command returns stderr, it is not piped to the ...
0
votes
1answer
49 views

Prevent a certain command

Is there a way to prevent a certain command in a folder or globally? I just need to prevent git merge staging I've tried with git hooks but with no success.
0
votes
1answer
56 views

Understanding the limits of bash token substitution

bash has token substitution, either via the $() syntax or via the `` syntax, eg: $ $(echo "echo hi") hi AFAIK, that works like so: first evaluate the inner command: echo "echo hi", which outputs ...
0
votes
1answer
16 views

How to read content of file and set it to a variable using bash shell within dockerfile?

I need to read content of the credential file into the variable MYPASS (can be defined also as an ENV), then printing out it calling echo within my Dockerfile. I tried a lot of ways, but couldn't ...
1
vote
2answers
32 views

Read a line then append pound sign (#) at the start of it based on a condition

I have a bash script which reads a file having multiple line of text and executes a command on those lines. Sometimes the command work, but sometimes it fails. I want to append a pound sign (#) at the ...
-1
votes
1answer
61 views

Bash script, error “Arg list too long”

I need to run a bash script in a .lua file: os.execute ("/path/to/file.sh") file.sh: #!/bin/bash route add 149.36.98.78 reject The permissions for file.sh is [-rwxr-x---] root www-data I'm ...
0
votes
3answers
52 views

Delete files same name but different file extension

I have a mess in my photo libary. I have files like these: image-1.jpg image-1.jpeg image-2.jpg Now I want to delete all photos with the extension .jpeg when there is a file with the same name but ...
0
votes
2answers
43 views

How do I combine two arrays in bash, by summing like-indices?

Say I have two arrays (or an array or arrays!) in bash like so a=(1 0 1) b=(0,1,1) how do I combine them into: c=(1 1 2) Where each element is added together to make c?
0
votes
2answers
26 views

Can I assign multiple data entries to one variable & if so how?

I'm using Linux Bash/Shell and i would like to know how to assign multiple separate data entries to one variable. For e.g. list of teams. each team needs data of: total goals scored at home - total ...
3
votes
2answers
123 views

specify a time interval in which to execute a certain script

I have this bash script: while [[ 1 ]] ; do sleep 3600 ; ./notify.sh --text "ricordati di bere" && play /mnt/musica/login.wav && zenity --info --text="<span size=\"xx-large\">...
0
votes
0answers
32 views

Delete a character from the last line of a bash array

I would like to do the same thing as this topic but with bash in version 4.1.2. I can get the chain I want with the following command: echo ${arr[@]:(-1)} | sed "s/,$///" However, I would like to ...
4
votes
1answer
378 views

Bash prompt takes only the first word of a hostname before the dot

I configured my machine as the following hostname ( in reshat 7.2 ) digi.master01.usa.com but my prompt is like this [root@digi ]# while we want [root@digi.master01 ]# any idea how to change ...