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

4
votes
2answers
54 views

Coming back to a command I have partially written [duplicate]

Often I find myself partway through writing a long command (or chain of commands) and realise I need to run another command before I can finish typing out this current one. Examples Sometimes, I... ...
1
vote
2answers
207 views

Why do I have double slash here?

$ which mycommand /home/t/program_files/document/other edits//mycommand Why do I have double slash // here?
1
vote
1answer
31 views

Using parameters in a script

I usually use the find command to automatically copy certain multimedia files from directory A to directory B. I use the following command: for f in `find ./ -name "*.mkv" -mtime -24h`; do cp $f ...
0
votes
1answer
46 views

Double quotes in bash

I am trying to create a bash file which calls a program that expects a parameter to submitted between two double quotes. Take a look at my file content. #!/bin/bash echo ./yowsup/yowsup-cli demos ...
1
vote
1answer
24 views

decrypt and unarchive file embedded in the script

I'm trying to create a self-extracting encrypted archive. Here's code that doesn't work for me: openssl enc -aes-256-cfb -salt -d -a | tar -x -j <<EOF ...
1
vote
1answer
20 views

Sort packages by size one-liner as function

While surfing web I've discovered nice one-liner that suits my needs well expac -s "%-30n %m" | sort -hk 2 | awk '{print $1, $2/1024/1024}' | column -t| However all the functional needed I got used ...
-1
votes
1answer
29 views

AWK and Bash Scripting [duplicate]

How to use a value of a variable in awk? Something like this: filename = "test.txt" ls -l | awk '{ if ($9 == filename) print("File exists")}' I can't use $ in awk to access the value of ...
5
votes
1answer
107 views

using ! character in echo

I am messing with echo and having issues with echo displaying the ! character. I tried this. echo -e "Wake!\nUp! bash: !\n!: event not found Then this # echo "Wake\!\nUp!" Wake\! Up! Well now ...
4
votes
2answers
159 views

Using bash's `/dev/udp`, how would I know if the port was open?

I do not have access to netcat or nmap so I'm trying to use bash and the /dev/udp/ special files to test ports. I could do something like: echo "" > /dev/udp/example.com/8000 But $? is always 0 ...
0
votes
1answer
42 views

i don't know what's wrong with the code below. it says 'unexpected end of file' [closed]

export FF=../list3.faults export CIR=../b22_opt_C.bench if [ -e redun ] ; then rm redun fi date > opendate ./atalanta -u -U redun -t .test1 -f $FF -b 1 -B 1 $CIR > text; date > ...
2
votes
3answers
28 views

Rename multiple files to their suffixes

I need a way to rename a couple of files containing spaces. I have: >ls Garbage Foo1.txt Garbage Foo2.txt Garbage Foo3.txt Garbage Foo4.txt ... And I need: Foo1.txt Foo2.txt Foo3.txt Foo4.txt ...
2
votes
1answer
49 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
88 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
12 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
87 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
81 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
58 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
65 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
20 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
786 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
38 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
206 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
43 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
75 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
27 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 # ...