Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

-1
votes
2answers
49 views

How to remove only 0-9 character long numbers from a file?

How can we remove only the numbers that are 0,1,2,3,4,5,6,7,8,9 character long from a file? I mean the lines that are matching this pattern. Example for removable lines: cat input.txt 1 123423113 ...
13
votes
1answer
233 views

Is there a difference between prepending a name-value-pair to a command and using env in bash?

Let's say I invoke A=B command and env A=B command in bash. Is there any situation where there might be a difference between both invokations?
1
vote
5answers
72 views

How to move a file and change its name without retyping the name and just add the new characters

I change too frequently the location of some files generated daily. The thing is that I want to change their names by only adding the new required characters. What I want is something like this: $ ...
0
votes
2answers
821 views

“Expect” automation tool output to shell variable

#!/bin/bash # more commands here expect << EOD spawn telnet localhost 9151 expect -exact "Trying 127.0.0.1...\r Connected to localhost.\r Escape character is '^]'.\r" send -- "AUTHENTICATE ...
0
votes
1answer
1k views

Changing title without changing prompt on Cygwin

I have the following shell script function from this site that allows me to change the title in both Putty and Cygwin. In Putty connected to a Linux host it changes the title and leaves the prompt as ...
0
votes
2answers
49 views

bash history for current session

Maybe I'm overlooking something but is there a way to get your current bash history for the current session you are using like if i run ssh host $ pwd $ ls $ cd /tmp I just want to see those 3 ...
0
votes
1answer
19 views

executing commands in shell and turnoff the default displays of commands in console

This is my script cd /opt/product/vinoth -- some operations -- cd - While executing this command cd - the old path get displayed in the console. is there is any way to block this from displaying ...
2
votes
1answer
38 views

Find Command: File Path vs -name Argument

I'm currently building a script to handle some files in a directory. In the first example, I use the find command and pass a directory in as the argument. In the second I instead use the -name switch ...
3
votes
2answers
144 views

Sed: modify every non-first word repetition for every word in text

Can you help me to do something like that using sed? qq ab xyz ab qq aa ab Becomes: qq ab xyz +ab+ +qq+ aa +ab+
0
votes
2answers
48 views

bash NOT reading .bashrc on RHEL 6

machine A --RHEL 7 and updated. machine B -- RHEL 6 and updated. If I do this on A (RHEL 7) ssh B I get in, like I should, but my .bashrc has NOT been run. This is new behavior to me. I want ...
1
vote
0answers
35 views

Repeatedly execute bash command while there's no output from another process

I'm running fs_usage to detect access to an object on my filesystem. sudo fs_usage -w | grep -E 'object' I now want to run a touch command on that object every 5 seconds as long as there's no new ...
3
votes
4answers
1k views

How to use the grep result in command line?

When I use grep to find some text which I need, it will display lines containing a match to the given pattern. For example, # grep -r ".*Linux" * path0/output.txt:I hope you enjoyed working on ...
0
votes
2answers
42 views

Bash assign $1 value

#!/usr/bin/bash kill9="9" kill15="15" if [ $1 == $kill9 ]; then set -- "$1" "$kill9" else set -- "$1" "$kill15" fi echo $1 I want $1 to become 9 if I type -9 and 15 if I type -15 My script ...
0
votes
2answers
57 views

problem with grep -f list of pattern

After searching, reading and trying possible solutions for much about grep lines with the list of patterns, hence I am writing. It is I know a very basic and have been attended in many forums. But I ...
10
votes
3answers
288 views

bash: Some issue when using read <<<“$VARIABLE” on a read-only root partition. Any known workarounds?

Just by coincidence I had to use my ATA-ID-to-device-name script (found here: http://serverfault.com/questions/244944/linux-ata-errors-translating-to-a-device-name/426561#426561) on a read-only / ...
3
votes
1answer
105 views

Reading char-by-char silently does not work

I'm trying to read user input char by char, silently, as follows: while [ 1 ]; do read -s -N 1 ... done While this loop works perfectly using VNC (xterm), it works only partially using putty ...
0
votes
2answers
44 views

How can I capture two columns of ls output in a bash script

I want to create a script to delete any directories with numeric groups. What I have so far captures and analyzes the group: #!/bin/bash re='^[0-9]+$' for x in `/usr/bin/ls -l /var/indexes | sort ...
1
vote
3answers
46 views

Remove old directories according to directory's name?

In my bash script I create a directory each month for backups as follows: DAY=$(date -d "$D" '+%d') MONTH=$(date -d "$D" '+%m') YEAR=$(date -d "$D" '+%Y') mkdir -p /var/app/backup/$DAY$MONTH$YEAR ...
4
votes
2answers
39 views

How do I convert a string into a number interpreted in certain base in bash script?

I'm simply trying to convert a string $RECORD_HDR to a number $RECORD_SIZE, where echo $RECORD_HDR gives 003D and echo $RECORD_SIZE should give 61
-1
votes
0answers
23 views

Ping Printer then Execute Command

I have many printers on my network using CUPS and a few pause occasionally. I can't find any consistency between them to isolate the cause so in the meantime I've made a script to view all paused ...
-1
votes
1answer
25 views

Run a server and client in a makefile [closed]

I'm coding a socket file server in C++, and I can't figure out how to put proper unit testing into my makefile. My problem is as follows: The server, when started, spits out its port number to ...
1
vote
1answer
39 views

BASH Program to remove files, Integer expression expected

# # if MAXFILES is not set, set to 10 # if [ -z "MAXFILES" ] then MAXFILES=10 fi # # now check to see if the number of files being removed is > MAXFILES # but only if MAXFILES = 0 # if [ ...
0
votes
1answer
26 views

Shell glob expansion after loop variable substitution

How can the following be changed example so that it does glob expansion after loop variable substitution? for i in a b c do echo $i/*.txt done UPDATE: This normally does work, however set -f ...
1
vote
0answers
24 views

Dynamic ~/.ssh/config

I'd like make my ~/.ssh/config file dynamically generated by a shell script (or anything else that prints to STDOUT). Is there a UNIX trick to make reading a file result in executing a command & ...
2
votes
2answers
29 views

Inheriting Bash signal traps

I'm struggling to find clear, unambiguous information about how the trap command works. In particular, is the effect of trap local to the script where it appears? I had always assumed this to be the ...
8
votes
3answers
4k views

ASCII binary tools?

Which is a good tool to convert ASCII to binary, and binary to ASCII? I was hoping for something like: $ echo --binary "This is a binary message" 01010100 01101000 01101001 01110011 00100000 ...
4
votes
2answers
401 views

Convert every pdf in the current directory to png

I want to write a bash script to convert every .pdf file in the current directory into a .png file. For example: $ls . a.pdf b.pdf $./pdf2png.sh Converting pdfs to pngs a.pdf -> a.png b.pdf -> ...
4
votes
3answers
5k views

How do I kill all screens?

I accidentally created over 1000 screens. How do I kill them all with one command? (Or a few)
0
votes
2answers
90 views

Remove a carriage return with sed

I have a large CSV file. One of the fields contains an error. This error appears as a new line in the file. Since now i've been using notepad++ with this command to correct the problem : \r";" ...
0
votes
1answer
133 views

Run bash script on startup in Linux Mint and open mate-terminal automatically

I'm new to Linux, so not sure how to do what I want. I have my_script.sh (executable, of course) like this: #!/usr/bin/env bash mate-terminal -e "bash -c 'cd ...
0
votes
0answers
7 views

Why does rbenv not get added to the path when bash -lc is called from a crontab job? [duplicate]

I'm trying to setup a cron job to back up a rails project using the whenever and backup gems. I have done a standard install of rbenv on Ubuntu to manage my rubies. In .bashrc export ...
3
votes
2answers
191 views

Append timestamp of last edit to filename

I would like to add the time of the last change to the file to its filename using the bash. For example this output of ls -la: -rw-rw-r-- 1 beginner beginner 5382 Dec 1 17:18 B_F1-1.xml should ...
12
votes
3answers
3k views

Bash subshell creation with curly braces

According to this, placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. Using ps to see this in action This is the ...
1
vote
2answers
37 views

Why doesn't my regex work in bash “if”? [duplicate]

Here is my code: if [ -f /Applications/xml[0-9].pl ] I also tried with -f =~ and double brackets but none seem to work. I first though that the regex might be faulty but I tried this. echo h1 | ...
2
votes
2answers
33 views

Checking and Killing processes of a user before deleting

I am working on a script to delete users from text file. However, before deleting, I wanna check if any process by a user is running and if running then kill all the processes and delete. Here's how, ...
0
votes
2answers
48 views

Bash regex string manipulation bug

I have an issue with bash and its regex match ability that I for now think is a bug in bash but could also be me having missed something obvious. I hope it is the latter. I have made this function in ...
0
votes
1answer
26 views

How to copy a whole directory structure with a certain file size limit? [duplicate]

For some reasons, I need to do a data clone. In which I need to copy the whole structure of a huge directory, but I'd like to only copy those files which are smaller than 1MB(with their hierarchy ...
2
votes
0answers
16 views

Remove tar compress spool from cron email

I have a crontab job that call a simple script to backup a website: 15 0 1,10,20 * * /home/username/bin/backup_whatever This is the script: #!/bin/bash TODAY=$(date +"%Y%m%d") ...
1
vote
1answer
24 views

get only file name while iterating over directory instead of path with it [duplicate]

$ script.sh -i /storage/testFile -i stores the path of /storage/testFile/. I want to iterate over file in testFile. Everything goes good, but I want to make this code cleaner and add a directory ...
1
vote
1answer
19 views

Trying to generate random pass for users and saving them in a file

I'm trying to generate random pass of the users created by a text file in a bash script and then saving those passwords into a text file.. That's how I'm doing.. It works fine and creates user from ...
1
vote
1answer
29 views

Print newlines on command output

If I get the result of a command on a variable, how can I print this output with new lines. Silly example: XX=$(ls -l); echo $XX When I execute the above sentence, I have one line ilegible result ...
3
votes
3answers
134 views

awk + print lines from the first line until match word

I want to print all lines from file until the match word please advice how to do that with awk for example I want to print all lines until word PPP remark the first line chuld be diff from AAA ( ...
1
vote
1answer
30 views

Compare directory trees regarding file name (and size and date)

I want to check the results of a restore from backup. This is, because TimeMachine on MacOS gives me some weird errors and warnings and I want to make sure, everything is in its place again after ...
-3
votes
1answer
29 views

How can I apply floating point discounts and taxes in a shell script?

I want to input a number and then add taxes and subtract discounts. I am trying: #!/bin/sh printf "Please enter purchase amount: " read purchase_amount if test $purchase_amount -lt 1000 then ...
2
votes
4answers
4k views

Bash eval array variable name

Here is my bash case: First case, this is what I want to do "aliasing" var with myvarA: myvarA="variableA" varname="A" eval varAlias=\$"myvar"$varname echo $varAlias Second case for array variable ...
4
votes
3answers
109 views

How to append a date to all files in a directory without touching sub-directories via bash script

I'm currently taking a class for Operating Systems and we're learning to do bash scripts as part of the curriculum. I need to append the date to all the files in a directory without touching ...
1
vote
2answers
34 views

Map reading/writing a file to getting output from/sending input to a script?

Suppose I have two scripts, script1.sh and script2.sh. I am wondering if there is a way to make a filesystem interface such that, for example, I can go vim file and then have my system run script1.sh ...
1
vote
0answers
24 views

redirecting output of running background job in bash

in bash I have some jobs running, in background. They are always producing random irrelevant error messages that pollute the terminal. I am not always so prompt to start them with the 2>&1 > ...
2
votes
3answers
64 views

Bash: issuing trap twice

I have a very simple question. I can't believe the Bash manpage doesn't explain this already, but anyway... If I issue the trap builtin twice [for the same signal], what happens? Is the second ...
4
votes
2answers
7k views

Bash vulnerability CVE-2014-6271 (Shellshock) fix on Debian 6.0 (Squeeze) [duplicate]

I upgraded my old Debian 6.0 (Squeeze) server, but still the vulnerability seems to be there: $ env x='() { :;}; echo vulnerable' bash -c 'echo hello' vulnerable hello How do I upgrade Bash to ...