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

2
votes
1answer
48 views

bash ssh warning when connect to raspberry: setlocale: LC_ALL: cannot change locale (en_US.UTF-8) [duplicate]

I tried for example this to solve my problem and this too. My problem is that when I try to connect to my Raspberry pi2, I got the following messages: Linux raspberrypi 3.18.7-v7+ #755 SMP PREEMPT ...
2
votes
2answers
86 views

How to delete old backups based on a date in file name?

I have a daily backups named like this: yyyymmddhhmm.zip // pattern 201503200100.zip // backup from 20. 3. 2015 1:00 I'm trying to create a script that deletes all backups older than 3 days. The ...
1
vote
1answer
52 views

Bash: using both way redirections in a shell script

I'm writing a shell script to compress and backup certain files. This will compress and move large files with sizes up to 4 GB. I'm having trouble with this line: gzip < $filelocation > ...
0
votes
0answers
9 views

How to convert Ubuntu init script to Amazon Linux AMI init script?

I had a Ubuntu based Amazon EC2 server where I was running my java based application. For this I had written a init script which was running perfectly and as follows #! /bin/sh # set the environment ...
3
votes
3answers
86 views

Delete folders which not match a list

I need practical example how get rid folders which are not in the list in Linux. So i do not need to compare its contents or md5sums, just compare folders names. For example, one folder has few ...
1
vote
2answers
33 views

dialout group missing

I have debian8, (Jessie) and I am trying to add a user to the dialout group. Alas, that group doesn't exist. I would prefer not to add the user to the root or sudo group. what should I do? ~$ ...
2
votes
4answers
80 views

Add 0 in the middle of a filename

$ ls pro2e_u01_txt_vocabulaire_11_descriptiveadjectives.mp3 pro2e_u01_txt_vocabulaire_12_nationality.mp3 pro2e_u01_txt_vocabulaire_1_campus.mp3 pro2e_u01_txt_vocabulaire_2_personnes.mp3 ...
2
votes
1answer
57 views

bash - wrong key sequence bindings with control+alt+space

I am trying to install some key sequence bindings but I have trouble. My shell is bash, my terminal is gnome-terminal, and my system is Ubuntu 14.04 in graphic mode. Edit : my keyboard is french ...
0
votes
2answers
62 views

How to delete specific lines within a certain area?

I want to delete some specific lines in the YAML front matter: --- Author: aaaa Title: bbbb Time: cccc Place: dddd ... Lets say I wanted to delete only the lines in the front matter that contained ...
1
vote
1answer
46 views

How to Prompt the user to press Enter to Exit in terminal so that the terminal doesn't close automatically?

Here is my Port.sh file echo 'Give me a maximum of 5 seconds to run please.' lsof -i | grep Xvnc | grep ESTABLISHED | grep $USER lsof -i | grep $USER | grep Xvnc | grep -o -P '(?<=:).*(?=->)' ...
4
votes
4answers
1k views

Why does `rm -f !(/var/www/wp)` leave files behind in /var/www?

Why does the rm -f !(/var/www/wp) command have no effect? I want to remove all the files in /var/www, except for the /var/www/wp directory, which should remain. root@born:~# ls /var/www ...
0
votes
1answer
19 views

mkvmerge in a bash script does not execute

I have made a script which does mux a videofile, multiple audiofiles and multiple subtitles into one .mkv. the script tries to run: "/usr/bin/mkvmerge" -o "test.mkv" "--default-track" "0:yes" ...
-1
votes
3answers
38 views

Error in `for` loop in `if… else` conditions

Hi guys I am new in writing bash script. I have a task to do. I have a file in which node name and IP addresses are updated, I have to make each file of those nodes which are not in our required ...
1
vote
3answers
47 views

BASH getopts more arguments after option

how can I make getopts take 2 arguments after -h option? I mean it is supposed to be saved in array but either it doesn't work, or I am making mistake by writing it down like this: echo " ${array[1]} ...
0
votes
1answer
35 views

BASH function to read user input OR interrupt on timeout

I am trying to write a BASH function that will do x if program a or b finish. example: echomessage() { echo "here's your message" if [[sleep 3 || read -p "$*"]] then clear fi } In this ...
4
votes
2answers
198 views

BASH base conversion from decimal to hex

In Bash, how does one do base conversion from decimal to another base, especially hex. It seems easy to go the other way: $ echo $((16#55)) 85 With a web-search, I found a script that does the ...
1
vote
3answers
51 views

How can I create a relative symlink given a relative path?

I would like to programmatically find the directory depth of a relative path. So for example the depth of test/dir/hello is 3 More specifically I would like the directory depth so that I can create a ...
0
votes
1answer
30 views

BASH getopts OPTARG undefined

I have this code, and when I call it in command line, it shows the echo in option/the one I have in each option/ but $OPTARG is undefined. And I have no idea why. OPTIND=1 optm= optl= ...
2
votes
2answers
31 views

How to transform string with character codes into quoted form

I have a string like New\x20Folder. Special characters is represented by their codes. I'd like to transform the string into quoted form: "New Folder". The only available tools are bash and bunch of ...
2
votes
2answers
33 views

check “newness” / “is-read” of /var/spool/mail/$USER like pam_mail for custom motd script

How can I check with bash or python (preferred) if there are some unread mails in /var/spool/mail/$USER like pam_mail does? I'd like to use this for my own custom motd script, motd.dynamic
0
votes
1answer
26 views

Use sed as argument for basename

I have this code so far... for i in {1..200}; do sed '$i,0!d' md5list.txt | grep -a ": "; done I would like to run basename for each iteration of the code above, like so: basename $(for i in ...
1
vote
1answer
75 views

bash bad interpreter and permission denied

I installed RHEL 5.1 on a virtual machine. I would like to install VMware Tools, but I keep getting an error. I am performing the installation via the tar procedure. I get the following error: bash: ...
1
vote
4answers
92 views

How to increase the amount of previous command text bash will scroll to?

I am try to debug an nginx configuration file with tail -f /var/log/nginx/error.log with error logging level set to debug (very verbose). the amount text the passed into error.log is maybe 5-10 ...
-1
votes
0answers
34 views

How can I encrypt specific words in a text file with a bash script? [closed]

I want to encrypt same words in a text file and I want to know how I can do it in bash. For example, if the file contains: The employee Kim Van, his registration number is ID721 he is work in the ...
1
vote
0answers
29 views

Printing to the terminal after boot

I am attempting to start a script that echos to the terminal once matchbox-terminal is loaded. I am able to run the script if I execute it in the existing xsession script located in ...
1
vote
1answer
67 views

bash: The prompt gets visually broken [duplicate]

The idea of my PS1 configuration is to show some extended info like Mercurial or Git repo status, command execution time, etc. The prompt is split by two lines because it produces too many characters ...
-1
votes
2answers
33 views

BASH getopts problem

Does anyone know why it doesnt do anything? moznostm= moznostl= moznosta= moznostb= while getopts ":m:l:b:a:h:" OPTION do case $OPTION in m) moznostm=$OPTARG echo "bol zadany argument $moznost" ;; l) ...
5
votes
8answers
785 views

How to put sentences on separate lines on Linux

I have an assignment to put sentences in a text file on separate lines. Something like this almost works: cat file.txt | tr '.' '\n' But I don't want to lose dots, question marks and exclamation ...
0
votes
1answer
40 views

introduce a c script in a bash file [closed]

My problem is to recover data keyed in text file in bash. I seek the command that can perform this task and I used sed, awk and even cut but I have not succeeded. One friend of mine suggested to ...
-1
votes
1answer
37 views

cron/ bash is not working via scripting, scoping issue?

I'm trying to schedule a task to run ever minute using cron: * * * * * /home/yzm/simple.sh >> /var/log/cron.log and this returns: bash: yzm: command not found cd-ing out of that folder: cd ...
8
votes
2answers
205 views

How bash treats “> >()”

While experimenting with output redirection and process substitution I stumbled upon the following command and its resulting output: me@elem:~$ echo foo > >(cat); echo bar bar me@elem:~$ ...
0
votes
2answers
62 views

Read lines and match against pattern

I can't figure this out. I need to look at every line in file and check out whether it is matching word which is given in variable I started through command read, but I don't know what am I supposed ...
2
votes
3answers
81 views

How to run multiple scripts in parallel

I have one bash script which calls the same perl scrips in a serial way. The bash script is used to collect the overall results, while the perl script collects the results of my simulations for the ...
0
votes
2answers
42 views

Redirect script output to /dev/tty1 and also capture output to file

I want to display text output on the console that is always displayed on a small screen on my Raspberry Pi. The following code works for showing that text output: cd ...
1
vote
1answer
45 views

awk pattern with variable in a bash script

I have problem with command awk in bash I want to find pattern with variable, but it doesn't work. Can you tell me what's wrong with this line? awk -F" " "/$PWD/ {print $1,$3}" file.txt
1
vote
3answers
34 views

access elements in string array - stray @ symbol

I have created an array (3 elements), and each element contains a comma delimited string. The array was created by reading a file line by line - the file contains fields output from a database. I have ...
0
votes
3answers
74 views

In BASH is there a way to read Variable names from a variable? [closed]

This is a bash question (hence posting here in Unix&Linux) I have a while loop that reads from a csv; It looks something like this: while read NAME PRETTY_NAME DESC; do echo $NAME done < ...
-1
votes
1answer
22 views

writing a script using killproc

Okay, I have an assignment and I am very very new to Unix. Here is what I am trying to do: I wrote a script to kill a running process. I have to use the command killproc..I just dont know where to put ...
1
vote
3answers
26 views

read -e in a sub script

Let's imagine that I have script1.sh and script2.sh with the following sources: Script 1: #!/bin/bash # script 1 echo "Doing some stuff..." bash script2.sh echo "Done" And Script 2: #!/bin/bash # ...
1
vote
1answer
52 views

Begin a glob with an exclude pattern

I am trying to tweak some completion. Suppose I have: $ ls bar.baz foo_bar.baz foo.bar If I want completion to match all files that don't end in baz: $ shopt|grep extglob extglob on $ ...
1
vote
3answers
46 views

What does || mean in bash? [duplicate]

Apologies if this is a duplicate post. I did try searching to see if someone already asked/answered this but didn't find anything. What does || mean in bash? For example, in researching steps to ...
1
vote
3answers
132 views

lines with unique checksum

I have a file A of lines of equal length n. I have a program that for each line in A can output a line of length n which its key. The program can either write the sequence of keys for the lines in A ...
3
votes
2answers
90 views

how to execute a bash command in a python script

How can I launch a bash command with multiple args (for example "sudo apt update") from a python script?
3
votes
2answers
218 views

remove ^M from solaris by perl one liner on the same file

usually in order to remove the ^M from file we do dos2unix test.txt test.txt tr -d '\r' < old.file > new.file but this approach insist to create new file if we do not want to create another ...
-1
votes
1answer
46 views

To use several parameters that are in a .lst [closed]

I've a doc.lst that is : 23/02/2015 0 AAA 23/02/2015 0 AB1 23/02/2015 0 AC2 23/02/2015 0 FRR 23/02/2015 0 FPT 23/02/2015 0 PEI 23/02/2015 0 PEA I would like to ...
0
votes
1answer
17 views

Linux 'w' command, get IDLE time in seconds

I need to get idle time of all users in seconds (not minutes or days), how do i go about doing it ? This command lists the idle times of all connected users : w | awk '{if (NR!=1) {print $1,$5 }}' ...
3
votes
2answers
68 views

save the number of files only in a specific folder

I'm using this script to save the number of files in a main folder, but it also counts the subfolders inside that main folder. nfiles=$(ls -1 /home/userA/mainfolder | wc -l) Any advice how I can ...
-1
votes
0answers
27 views

SSH Session Hangs - Custom Way of Checking It

So, the hanging of the session is not the issue by itself - I am aware of it, I know its root cause. I am interested in a rather custom solution for checking if the session hangs. I am inspired by ...
1
vote
2answers
34 views

How to copy only files in a specified directory to another folder

I'm trying to copy only the files from one directory (not including folders or any files in its subfolders) to another location using cp /media/d/folder1/* /home/userA/folder2/. It is copying the ...
0
votes
1answer
76 views

Read only specific lines from text file and save matches into variables

I've got this problem. I need to extract some words from text file, which I find by specific pattern in that text. For example: /this/is/path: file1.txt,date-3 file2.txt,date-2 /this/is/path2: ...