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
0answers
14 views

Bash Script — ffmpeg not being invoked as expected

I'm working on a bash script to convert my music library to ogg* but executing the right command is somehow eluding me. This is the line that should accomplish it: ffmpeg -i "${file}" -f flac pipe:1 ...
3
votes
2answers
96 views

When should one use $( ) in defining variables

Some shell scripts I have come across use the following syntax when defining variables: file_list_1=$(echo "list.txt") or file_list_2=$(find ./) I would have used: file_list_1="list.txt" and ...
2
votes
1answer
20 views

What is a “checksum” and how do I use it from the shell?

I've seen on a lot of sites "checksum" hashes to verify the integrity of downloaded files. What are them and how do I use them? Ex: I have a downloaded-file.tar on the current working directory and ...
1
vote
2answers
26 views

Url Decoding shell script

How can I store the url-decoded string in a variable using shell script #!/bin/sh alias urldecode='python -c "import sys, urllib as ul;print ul.unquote_plus(sys.argv[1])"' ...
1
vote
0answers
20 views

Is it possible to create aliases that affect services starting?

Currently I have a custom service that executes java in multiple places. I want to be able to add an option to any executions of java this service will spawn (I'm specifying the error log location, ...
7
votes
2answers
84 views

Keeping history per working directory (cf. per shell session)

Is there a way to make a modern shell's history feature be scoped to a path? My working contexts are split up as paths on the file system, and the pattern of shell activity, such as repeatedly issued ...
9
votes
1answer
66 views

Why is nullglob not default?

In most shells nullglob isn't the default. That means, for example, if you run this command ls * in an empty directory, it will expand the *-glob to a literal ' * ', instead to an empty list of ...
2
votes
1answer
22 views

Return code for curl used in a command substitution

I've script as below :- httpUrl="http://www.nnin.com" rep=$(curl -v -X POST -d "UID=username&PWD=pass" $httpUrl) echo $rep when I run the script the return code always $?=0 because in a way ...
6
votes
2answers
256 views

How can I end a here-document that starts with <<\\$fff?

I was asked the following question in a test on shell scripting at my university, which never gave an answer, and google is of little help. Q: What is the line separator that should be used to end ...
13
votes
3answers
301 views

Prepare answers for questions of a command

Let's say I want to write a shell script that executes just one command. But this command is poorly designed. It doesn't offer any command line options; instead it asks some questions and waits for ...
1
vote
0answers
36 views

Shell Script to change user shell

I am writing a script that would be invoked to change user shell. The basic requirement is that once user gets authenticated (e.g: thorough some web application) the script would be invoked to set the ...
0
votes
1answer
22 views

FDs more than 2, more than (stdin/stdout/sterr)

I think this post is not off-topic.We had three traditional file descriptors in Unix contexts: 0 == STDIN 1 == STDOUT 2 == STDERR But in new articles, blogs, posts, answers, or so on, I read more ...
1
vote
2answers
46 views

Compare three files: lines present in one, but not in the other using column comparison

I have three files file1.txt, file2.txt, file3.txt and they are of same format(same number of columns with same data type). I want to select records from file1.txt which are not present in file2.txt, ...
1
vote
2answers
42 views

Accessing fish functions from perl

In bash I can do: foo() { echo bar; } export -f foo perl -e 'system "bash -c foo"' I can also access the function definition: perl -e 'print "foo".$ENV{"BASH_FUNC_foo%%"}' How do I do the same ...
0
votes
1answer
22 views

Percent Signs for Shell Vars to Remove Extension [duplicate]

for file in *.pdf ; do newname=${file%\\.\*} done I don't understand how the %\.* is removing the file extension, can someone walk me through it.
3
votes
3answers
228 views

Extracting unique piece of text from file with awk, sed or grep

From the output of pactl list sink-inputs, I need to grab the sink input number for VLC. Before that, I'm trying to extract the piece that contains the output for only VLC. All the methods that I ...
2
votes
3answers
65 views

Help with String manipulation in shell

I was writing a shell script to generate a string in a particular format so that it can be used as a input in one of the XML I am working with. Given a input file in the format <attribute ...
3
votes
2answers
57 views

Is it possible to exec some commands in a subshell without immediately exiting afterwards?

I use the fish shell and would like to be able to "source" some shell scripts written with sh-compatible syntax, which fish cannot read. For example lots of software expects you to source some shell ...
4
votes
4answers
206 views

How can I copy a file in a bash script and rename it while copying and place it in the same directory

How would I copy a file "file.doc" and rename it while copying to "file_copy.doc" and place it in the same directory ? And this only by calling the script and adding the file name in the argument: ...
4
votes
4answers
68 views

Searching file in a directory through bash script

I have written the following code to search all the file names in the current working directory that contain the letter 'f'. for i in * do echo $i if [ $i = "*f*" ] then echo "no" else ...
1
vote
2answers
52 views

Run commands “without” terminal [on hold]

Months ago I saw a guy running commands from a small, text-box-like window, showing nothing else other than the text-box for you to write the command. Such text-box would popup by pressing some ...
0
votes
4answers
63 views

Hexadecimal number sequence checker in Linux?

I have a list of hexadecimal number. I would like to check whether they are in sequence or not. That is, they should be consecutive numbers, in increasing order. In other words, there should be an ...
0
votes
0answers
44 views

Shell script to send alert if mount point exceeds 75% [duplicate]

How to write shell script to send an alert if any file-system on server exceeds 75%, in one email notification instead of receiving separate alert email notification for each file-system. I am ...
2
votes
1answer
25 views

Generate SFV file, optimizing hard links

I'm currently running cfv -C -rr to generate a SFV file that contains the CRC32 checksums of all files in all subdirectories. The issue is that because there are so many hardlinks, this process is ...
1
vote
1answer
45 views

A question about shell and .profile,.bash_profile,.bashrc

I'm on aix 7.1,my shell is bash if i did ssh ibmunix gqlplus user/pass All works and gqlplus start,gqlplus is on /opt/freeware/bin If i did from another machine ssh ibmunix "gqlplus ...
7
votes
1answer
129 views

Why there isn't a new line at the end of quoting a subshell and passing the results to echo?

When I do ls | grep png the output of grep is: 2015-05-15-200203_1920x1080_scrot.png 2015-05-16-025536_1920x1080_scrot.png (filename,newline,filename,newline) then, echo $(ls | grep png) outputs: ...
13
votes
1answer
553 views

What's the magic that allows me to tab-complete remote files as I type an scp command?

Presumably this is a feature provided by some plugin I have enabled in my oh-my-zsh setup (I have been using zsh for many years now). I noticed ever since I added my public key to the server (now I ...
1
vote
2answers
59 views

How to perform grep on 'man unix_command'?

Often while going through the output of man man awk I Need to perform grep, for e.g. in man awk, I need to find the definition of a particular flag, variable etc. Can anyone tell me, what would be ...
1
vote
1answer
44 views

Searching a filename

How to search a file with a given String and currentTimestamp and if not found trigger a mail? For Ex-:I have to search a file whose filename would be like filename_05172015 and trigger a mail if not ...
0
votes
3answers
37 views

How can I add a line including single quotes to a file with sed [duplicate]

I want to append the following line to a text file with sed: gem 'forum2discourse' I've tried sed -i '$a gem \'forum2discourse\'' Gemfile but this drops me to a > prompt so I think I must be ...
6
votes
5answers
190 views

How to execute a bash command in all possible subdirectories?

Let's say my main directory is /home/test Under it i have lots of subdirectories and under subdirectories still a lots of them and so on. Example: /home/test /home/test/subdir1 ...
-2
votes
0answers
45 views

Convert perl to shell/bash [closed]

I understand C and C++ and new to perl scripting. I must convert the perl script under the following url to shell or bash: busware Here is the code: #!/usr/bin/perl use warnings; use strict; use ...
0
votes
0answers
39 views

How to rewrite the comand using I/O redirections?

Is there any way to rewrite the following command using only I/O redirections and not pipes ? ls -l | grep User | wc -l | tail -l
2
votes
4answers
87 views

Why . /home/Desktop is incorrect and ./Desktop is correct?

I'm learning about Linux, started yesterday. I have a question which I couldn't answer from my book or Google. What is the difference between ./ and / in the shell? I'm asking this because when I ...
2
votes
1answer
27 views

Reading keypresses in shell using trap and Unix signals

I am trying to grasp a fairly involved Unix shell (tested in bash) function that listens for keypresses. The full code can be found here. The part I am having trouble understanding is the purpose of ...
0
votes
0answers
18 views

Issues with Screen - Running Minecraft in a while loop through a screen session

So two days ago I changed my startup scripts for my minecraft server. Problem is, after about 3 hours, the screen for it that I was monitoring "mc" vanished and refuses to list when using -ls. The ...
0
votes
2answers
92 views

Can a command be executed without a shell?

I am developing a binary executable program command to execute programs and return the output into a text field. The parameters to the command involve the command itself as it would be typed on the ...
18
votes
5answers
516 views

Find files that a user can write, efficiently with minimal process creation

I am root. I would like to know whether a non-root user has write access to some files - thousands of them. How to do it efficiently while avoiding process creation?
0
votes
2answers
50 views

Can not execute command with root in a remote Linux host

I try to migrate shell code to Python fabric code. The issue I meets is that Python can not execute command with root in a remote Linux host. Could anyone meet this issue and figure it out? I am very ...
1
vote
1answer
34 views

Shell read script for sftp

I have this working: % cat read.sh !/bin/sh file=list.txt while read line do echo "$line" cut -d' ' -f27 | sed -n '$p' > file2 done < "$file" % cat list.txt sftp> #!/bin/sh sftp> ...
4
votes
5answers
86 views

command which works like ~ (tilde) symbol to represent some directory

cd ~/scripts. This will go into scripts directory in my home. Similar to this, I want some "alias" kind of setting, which will allow me to enter some other directory so that, cd xxx/mywork -> will ...
0
votes
1answer
33 views

Take output field data string into variable

I want to grep for some specific lines from a log file, and then capture a specific part of that output in a variable and use it in other commands. The grep command I have is the following, where $1 ...
2
votes
1answer
38 views

xargs not prompting after each line

I want to know the size of all the data files in my directory. I tried using the following command. The file names all start with data_. find . -name 'data_*' -type f | xargs ls -sh -n1 -p I do ...
3
votes
3answers
43 views

How can I list every port serving a web page

I have a number of servers, all with various HTTP(S) services accessible on a variety of ports. It's incredibly difficult to keep track of which service is available under which host and what port. ...
1
vote
4answers
210 views

Wildcards for filepaths aren't working in grep [duplicate]

I need to grep words like these: ABC-DEF AB2-DEF AB3-DEF AB-DEF So I was trying: grep AB*-DEF grep -w -AB*-DEF grep -w AB*DEF But neither of them are working. Please help.
1
vote
1answer
27 views

Restrict ssh access per user based on conditions

Is there a way to restrict a user to only use ssh to connect via SFTP, but disallow that same user to login to a secure shell terminal? I only want the user to have the ability to connect by an SFTP ...
1
vote
2answers
26 views

Separate bashrc file for ssh sessions to avoid Unison Errors

Recently my Unison started throwing up some strange error whenever I tried to sync between my laptop and my PC. I realized that I had added a line in bashrc that would print my pending tasks whenever ...
1
vote
2answers
43 views

Aliasing using for or while loop in .bashrc

Can I use a for or while loop when I have similar pattern in the aliases that I put in my .bashrc file? For example, I have: alias c0='ssh computer-1-0' alias c1='ssh computer-1-1' alias c2='ssh ...
0
votes
3answers
110 views

How to loop through lines in a file which contains * in each line

I have a file that contains about 800 lines. All the lines contains 1 * character in it. I need to loop through the lines in the file so I used the following simple for loop for i in $(cat ...
-1
votes
1answer
23 views

How can I execute and export in a single shellscript

I have two shell scripts. $ cat java_alternative_7 #!/bin/sh sudo update-java-alternatives -s java-7-oracle $ cat java_home_7 #!/bin/sh export JAVA_HOME=/usr/lib/jvm/java-7-oracle It's simple that ...