The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

1
vote
2answers
49 views

Invoking a script with sudo ignores the shebang

Invoking a script using sudo ignores the shebang and runs the script in a different shell. To test, I created a script (test.sh) containing: #/bin/bash echo "BASH is: $BASH" echo "actual shell is: ...
3
votes
2answers
101 views

How can I submit the input filename into find exec correctly?

I want to create two pdf output files of a single LaTeX source. One output file is public and the other one (with further information) is becomes public. I use a make file which uses find to grep ...
4
votes
1answer
97 views

How the terminal can run programs and show its output? [closed]

I'm slowly creating a mental model of how linux works, and I've tried to simplify the most, my model of how linux works. Let's assume that the kernel boots and inits the only software it's gonna run: ...
1
vote
1answer
19 views

Openssl generate invalid websocket security code

I need to write websocket server on GAWK. And server must handle user's Sec-WebSocket-Key by following algorithm (from RFC): Concat key with 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 Take sha-1 in binary ...
2
votes
2answers
30 views

Exported variables inside ssh session are empty

I am trying to export a variable inside a ssh session and reference the variable in the next write command. sshpass -p "password" ssh -t -t my-box <<EOF export newUrl="this is a url" sudo ...
1
vote
2answers
24 views

View current user process ancestors and formating the output

I'm using ps -eo ppid,pid,cmd to view all process, and how can I format the output to view like below? Only given PID and its ancestor will print (until init). 23464 current | 23211 bash | ...
4
votes
0answers
51 views

How to track an alias definition in Bash? [duplicate]

This is an alias defined in my Linux shell: $ alias vi alias vi='vim' This alias is so stupid that I want to delete it definitely. Is there a command to find where alias vi='vim' might have been ...
2
votes
1answer
63 views

Shell Script Loop Conditionally

I just create a new shell script and having trouble with small issue. Below is my script :- function mainMenu(){ while : do echo -e "\nMain Menu:" echo " A. Process Managements ...
-3
votes
1answer
38 views

shell script to sleep at an increment of 10 [closed]

shell script to sleep at an increment of 10 lines. I want my script to sleep for 3 mins after every 10 lines its read. then pick up from the last line. I'm not good with script, so I dunno where ...
0
votes
3answers
35 views

How to add two variables passed in the shell which returns integer count?

In my script I am using 2 variables: integer CCD_COUNT1= `grep '.CCD' $TMP_RPT_FILE1 | wc-l` It returns integer value suppose 47. Another variable: integer CCD_COUNT=`grep '.CCD' $TMP_RPT_FILE | ...
5
votes
2answers
315 views

Running remote command with ssh getting “bash: /dev/fd/63: No such file or directory”

I have /root/test.sh on a remote server, which has the following content: #!/bin/bash date On the remote server, I get the following output: # ./test.sh Fri Dec 18 07:41:10 EST 2015 # bash ...
3
votes
3answers
19 views

jump to current day's directory in a date based directory hierachy?

I have a pretty standard directory higherachy, year, month, date, for log files. If I want to go to todays logs I have to type cd logs/2015/12/16/ By itself this wouldn't be bad, but since I ...
5
votes
3answers
648 views

File name beginning with - (dash) [duplicate]

I have file called -l in my directory now I tried to do for i in *; do stat -c "%s %n" "$i"; done it lists all files with sizes but in the middle of the output there is something like 395 ...
0
votes
3answers
42 views

Matching lines in two files [duplicate]

Let's say I have two files, file1 and file2. file1: passd:xxx hopla:alli gnar:gungg araf:utap file2: alli utap How can i check what lines/words from file2 match file? Indeed I could probably do ...
6
votes
3answers
525 views

Meaning of [ “${1:0:1}” = '-' ]

I have the following script to launch a MySQL process: if [ "${1:0:1}" = '-' ]; then set -- mysqld_safe "$@" fi if [ "$1" = 'mysqld_safe' ]; then DATADIR="/var/lib/mysql" ... What does ...
0
votes
0answers
30 views

How to run a BBMap software .sh script in a for loop for a set of 100 .fasta files?

cd /home/user/Documents/bbmap ./bbmap.sh ref=fake.fa # indexes fasta format file sets ref filelist="fastaone.fasta, fastatwo.fasta, fastathree.fasta" for list in "$filelist" do ./bbmap.sh done Is ...
16
votes
4answers
719 views

How to trick a command into thinking its output is going to a terminal

Given a command that changes its behaviour when its output is going to a terminal (e.g. produce coloured output), how can that output be redirected in a pipeline while preserving the changed ...
3
votes
5answers
84 views

How to process special characters in in file name using find

I am to find all files that start with certail char , e.g find . -maxdepth 1 \( -name "^m*" -a ! -name "g$" \) -print but what if someone create file that has special characters in the name of that ...
2
votes
2answers
58 views

“cut” hangs when using “tail -f” in combination with “tr”

I'm try to pipe chat log files to some speech output, and want to remove timestamps with cut and remove special characters with tr. Unfortunately, cut seems to halt when using it with tail -f in ...
0
votes
0answers
41 views

How to minify Javascript and CSS with command-line using minify tool?

I'm not that versed in unix and I cannot have Java, so YUI Compressor does not apply, but I have this known Minify tool, which will get a minified version of a JS/CSS file from a specific URI ...
1
vote
2answers
162 views

cat command is not working inside shell script

I have the following line which is not working in ksh but works fine in sh cat `find /home/peter/databases -name "cells.txt"` This is working if this line is inside /usr/bin/sh script. But not when ...
0
votes
1answer
31 views

What is happening behind the scenes for these basic Unix commands?

I was just playing with some basic Unix commands with following operations create a file 'one' create a link 'two' to 'one' (ln one two) Edit the file 'one' and put words - one, two, three, four on ...
1
vote
2answers
15 views

Find doesn't work with recursion?

I ran the command below and notice it will only did the mod on the first level(SubDir*) on the finding and not the subsequence (ChildSubDir*). I wanted to ask if it is possible to go recursion on the ...
1
vote
1answer
20 views

Keep \ in read variable to show space [duplicate]

Trying to keep spaces in the variable for read with the \. $ echo "Drag folder to be copied to terminal and press ENTER." $ read FILE /Users/UserName/Desktop/Folder\ With\ Spaces\ In\ it $ echo ...
2
votes
2answers
121 views

gunzip from stdin

I have a large collection of gz files. I want to extract them all. Here is what I was trying to do: find . | grep .gz | gunzip However, gunzip does not accept list of files from stdinput. How can I ...
1
vote
1answer
32 views

A command that takes a single numeric argument and prints out the day of the week based on the formula

days=('Sunday''Monday') days=('Tuesday''Wednesday') days=('Thursday''Friday') days=('Saturday') for numbers in "S@"; do if [ $numbers -ge 0 ]; then result=$(($numbers ...
0
votes
1answer
43 views

Run git command to save output but consume STDERR too

I've tried: status=$(git status -s ./$name>&1) status=$(git status -s ./$name >2 /dev/null >&1) status=$(git status -s ./$name >2 /dev/null) status=$(git status -s ./$name > ...
3
votes
2answers
57 views

Changing file permissions according to their names

I created 512 files, with names made from combinations of permisions (r, w, x). I created them like this: touch ./{r,-}{w,-}{x,-}{r,-}{w,-}{x,-}{r,-}{w,-}{x,-} and I want the files to have same ...
1
vote
1answer
34 views

Assign path to variable which does not exist

In an effort of keeping things DRY, I am trying to assign a path to a variable that may not exist and have the following script which returns: /apps/tmp: No such file or directory #!/bin/bash ...
0
votes
1answer
67 views

shell find -delete “directory not empty” [duplicate]

i try to delete backupfiles on my synology nas older than 30 days, the files are in a directory which is created durig downoad the backupfile from my webserver after download i want to check -mtime ...
0
votes
1answer
46 views

Can not execute bash script (unexpected element '(' )

I have created a script to check if I have installed Node, Npm, Bower and Susy but when I execute it I get an error which I can not solve. This is the script: isInstalled(){ command -v $1 ...
1
vote
0answers
30 views

Is there a GNU/Linux equivalent to the Mac OS X open command? [duplicate]

In Mac OS X there is a handy open command that opens the target file or directory in the default GUI application meant for it: open /usr/local/share will bring up a Finder window with the ...
4
votes
4answers
123 views

Use awk interactively through a pipe

Looking at this question, I've noticed that awk can't read user input if the file is being piped into standard input, but it does behave as expected if reading input from a file given as a command ...
1
vote
2answers
90 views

Remove file with pound signs around it [duplicate]

I am using SSH to another terminal with very limited disk space. upon typing ls I see a file called #korpus.txt#. I suspect this file is an emacs buffer, but upon running emacs and trying to kill it ...
-4
votes
1answer
31 views

I'm using the following snippet for Log rotation

Can some one explain how this worksps -ef | grep mongod | awk '$0!~/grep/ && $2~/[0-9]/{print "kill -SIGUSR1 "$2}' | bash; find /tmp/logs/* -type f -mtime +7 -exec rm {} \;
3
votes
3answers
54 views

A bc problem about long expression

I want to calculate an expression in shell. I use the following code: pi=$(echo "scale=10; 4*a(1)" | bc -l) i=3 d=`expr (1+c($pi*($i/10)+$pi))/2 | bc -l` But it says bad pattern: ...
1
vote
1answer
58 views

bash adding 1 to variable in while loop [duplicate]

The situation is as following: I have a .txt file that includes series of letters all divided bij newlines Here's a small part of the file: lrtjxz lrtjhs lrtsxv lrtvsw lrtywj lrtyws lrxwwv lrvhsx ...
1
vote
2answers
39 views

Metasploit Directory Doesn't Run Executables Without ./

I have Metasploit installed on OSX in /usr/local/share/msf Metasploit's executables can't be run outside it's directory thus would give a command not found error. msfbinscan msfconsole msfd ...
4
votes
3answers
154 views

check if a string has a character more than once

The title actually almost explains it all. I would like to check if a string contains a letter (not a specific letter, really any letter) more than once. for example: user: test.sh this list ...
1
vote
1answer
47 views

C Shell Script syntax error “unexpected end of of file”

I am trying to write a c-shell script that checks for number of arguments and echos a string, but I am getting an unexpected end of file syntax error and I don't understand why. Here is what I tried: ...
1
vote
1answer
26 views

Why isn't this perl regex capturing the backreference?

I have a directory of files $ ls -1 ep2.mp4 ep3.mp4 ep4.mp4 ep5.mp4 ep6.mp4 ep7.mp4 I want to use the perl rename utility to make all files look like e.g. ep02.mp4 Command I am using rename -n ...
10
votes
3answers
1k views

Why is it rm -rf and not rmdir -rf

I've always been curious why the command for deleting everything in a directory is rm -rf. Why aren't there flags to do the same thing with rmdir? Wouldn't it be more intuitive to use rmdir for ...
3
votes
1answer
35 views

parallelize shell script

I have a following line: for length in "$(ls $OUT_SAMPLE)" do $CODES/transform_into_line2.rb -c $OUT_SAMPLE -p 0 -f $length & done So,it should parallelize the for loop but somehow it still ...
0
votes
1answer
40 views

Unexpected end of file inside of my bash script [closed]

I have a script #Check the disk space before backups are taken echo "Checking Disk Space" df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; echo $output ...
1
vote
1answer
35 views

Force SSH password prompt without restarting the service [closed]

I've met a problem when I configure SSH users in Centos7. There are two computing nodes, for example: hostname: node1 users: user1 user2 hostname : node2 users :user1,user2 If I input the ...
0
votes
0answers
25 views

Canvas(blackboard)-like program

I have to make a program that has most of the functions those websites have and I am stuck at the point where I have to get the grades from a file and use a formula to calculate the students final ...
1
vote
1answer
31 views

Relation between shell start up processes and environment of parent process

"How are shell variables related to the environment that a process started by the shell has on start-up?" I read If processes inherit the parent's environment, why do we need export? My current ...
0
votes
1answer
17 views

Help with the PS and TTY?

I have this question for you guys: I execute on a different shell 'sleep 600'. I open a different terminal and I executed 'ps' to see my current process , however , I dint see any sleep process. I ...
0
votes
1answer
56 views

How do I replace my “base system shell” with IPython?

I'd like to replace bash with IPython on my system, so that even files like .profile are in Python rather than shell script. I have some confusion on the topic, even though asking a few questions on ...
0
votes
1answer
45 views

How to get the latest text file based on timestamp from a directory

I am having a directory as /var/tmp/kick Where it has text files as CCD_FILE_120920150300033.txt CCD_FILE_121020150300035.txt How to get the latest file based on timestamp and copy the old file ...