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)

4
votes
3answers
287 views

Remove files by regular expression

I want to keep files whose names match [0-9A-Z]{1,2}_\d{4}_\w+?\.dat, for example, A1_2001_pm23aD.dat, K_1998_12.dat, and remove the rest. However, the ls and rm commands do not support such regexes. ...
0
votes
2answers
176 views

How can I redirect the same message to both stdoud and stderr (without temporary object)

It is easy to redirect stdout or stderr to the same output (file or one of the 2 std output) with a 1>&1,>&2 and/or >file. Is there a way to send the same output to both the std ...
0
votes
0answers
28 views

How do I make Web Service call in Shell Script? [closed]

Can I make a web service call in a shell script? For example, below is a web service call through cURL: curl -u graeme:abcd -i -F name=files -F filedata=@employees.csv ...
0
votes
2answers
39 views

How to change the language for man command? [duplicate]

I wanted to ask if it was possible to translate the man and man explanations from the terminal (in Italian language). If, for example, use: man cd Instead of running in English I would that will ...
0
votes
1answer
3k views

Any possibility to execute shell script from java file?

I have one Java file named app.java which extracts the servers in my application. I need to connect to every server in that list and extract the logs. In loop, I have to call script for connecting to ...
0
votes
0answers
38 views

Understanding bash script for getting drop down option

I have this script which reads the user input for executing some command, This is working fine. User=0 Path="/root/file/" Path1="/root/domain/samples/file" echo "Please select k1 l3 l8 o5 s2 s1 ...
1
vote
2answers
553 views

How do you keep the password hidden when invoked during the su command?

This is the first time it has happened to me where I am using the su command and it actually displays the password on the terminal and doesn't stay hidden. Here is my code snippet: sshpass -p ...
5
votes
5answers
5k 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: ...
14
votes
4answers
7k views

How to set window size and location of an application on screen via command line?

I want Firefox window to be opened in a specific size, and location on screen using a shell command, for example: firefox myfile.html size 800x600 location bottom-left Is there such a command?
0
votes
2answers
35 views

How to search for Viber app files

I am trying to perform filesystem extraction on viber app. my findings show that viber contains a folder named databases which contained files of interest, namely, Viber_messages, Viber_data and ...
0
votes
0answers
16 views

How do I submit a header with curl? [closed]

If I want to submit a header with curl (The header being “Authorization: Bearer token”), how do I do that? I wrote this script for bash curl -i \ -H "Authorization: Bearer fefef" \ -X POST --data ...
0
votes
2answers
45 views

Cron Job: Redirecting shell script output to a file

Just an one line shell script below not working as a cron job but executing directly from terminal works fine: #!/bin/bash echo "Executed" >> ./crond.log 2>&1 What might be the ...
2
votes
1answer
28 views

How to get a list to be entered in quotes

firstly I am a total n00b with scripting, so please forgive any incorrect terminology. I have a simple script that runs a python script (used to deduplicate emails via IMAP) after a user has entered ...
2
votes
2answers
89 views

Using tar with find

Lets say we want to find a certain files , use tar on them and delete them. I tried using touch "mycompress.bz2.tar" find . \( -name "*.c" -o -name "*.sh*" \) -exec tar ujf "mycompress.bz2.tar" {} ...
1
vote
0answers
15 views

cvs auto setenv and login without typing password again

Hi I'm trying to logon to cvs automatically every time I start the machine. This works well but I have to manually type cvs login in the shell: setenv CVSROOT :pserver:$USER@vlsj-cccc:/vols/cvsroot ...
0
votes
0answers
16 views

Admin scripts for RPi and ODROID XU4 on an automated UAV? [closed]

Please let me know if this isn't quite the place to ask this; I don't think that Super User was quite the place, so I thought I'd try here. I'm looking for ideas for bash scripts, or just general ...
0
votes
0answers
69 views

lsudo /sbin/ldconfig -v showing Garbage text

RHEL 6.6 When performing sudo /sbin/ldconfig -v while trying to follow a different stackoverflow question related to: sudo /etc/init.d/nginx restart /usr/sbin/nginx: error while loading shared ...
3
votes
2answers
329 views

Is it possible to make the variable inside nested for loop local

#!/bin/bash for i in 1 2 3 4 do # { # local i ##gives error local: can only be used in a function for i in 1 2 3 do echo "inner loop ----- $i" (( i++ )) done # } echo ...
3
votes
1answer
38 views

Bash: Why is read returning a nonzero exit status while reading my file?

I'm trying to read two files line-by-line in Bash and do something to each of their lines. Here is my Bash script: #!/usr/bin/env bash die() { echo "$@" >&2 exit 1 } extract_char() { ...
1
vote
1answer
1k views

How do you make case statements with ranges

I'm supposed to: Make a case statement that will display the a grade after input. With no loop or conditional. A=90-100, B=80-89, C=70-79, D=60-69, F=0-59 This is what I have so far: ...
86
votes
30answers
25k views

Quick directory navigation in the terminal

I would like to frequently switch between directories that are in totally unrelated paths, for example /Project/Warnest/docs/ and ~/Dropbox/Projects/ds/test/. But I don't want to type cd ...
10
votes
4answers
2k views

Why does “$(( ~33 ))” produce -34?

$ echo $(( 255 )) 255 $ echo $(( 33 )) 33 $ echo $(( ~33 )) -34 $ echo $(( ~255 )) -256 $ and my kernel is: $ uname -a Linux HOSTNAME 3.2.0-40-generic-pae #64-Ubuntu SMP Mon Mar 25 21:44:41 UTC ...
19
votes
4answers
7k views

Why does while [ 0 ] go into infinite loop?

I see the same behaviour for below loop as the loop with while [ 1 ]. Why is that so? while [ 0 ]; do echo "hello" done
0
votes
3answers
3k views

The best way to add Unix Shell variables to CURL GET request

Let’s say I use curl –X GET command with the following link: “$WEBSITE_URL/ACTION_NAME/ACTION1;id=$ID?Command=TEST&id1=$ID1&id2=$ID2&id3=$ID3” As you can see, there are some $variables ...
5
votes
2answers
499 views

Blank lines when executing “grep | xargs” in a “find -exec”

I'm trying to list all directories of a web server that are blocked by Apache via a .htaccess (containing deny from all). I've managed to get the list of blocking .htaccess but when I try to extract ...
3
votes
2answers
61 views

find latest file created in folder and grep contents

I have a need to search a certain folder for the newest created file and grep the contents for a pattern. I have had ok success so far using this command: find /var/log/folder -type f -printf '%T+ ...
0
votes
2answers
56 views

How to determine what IP addresses are available in a hosts table?

I'm working on a script that will read from the /etc/hosts file and determine what IPs are available in the hosts file. The way the hosts file will look is as followed: 172.17.164.2 System1 ...
36
votes
3answers
13k views

Are there naming conventions for variables in shell scripts?

Most languages have naming conventions for variables, the most common style I see in shell scripts is MY_VARIABLE=foo. Is this the convention or is it only for global variables? What about variables ...
5
votes
2answers
20k views

Execute shell script from php, as root user?

Need to execute the following line from PHP: $res = shell_exec('sudo sh /home/nicklas/cronjobs/make_account.sh username password'); The problem is nothing happens on execution. If i try to ...
28
votes
4answers
25k views

echo a file without the first and last lines

Is there a simple way I can echo a file, skipping the first and last lines? I was looking at piping from head into tail, but for those it seems like I would have to know the total lines from the ...
1
vote
2answers
38 views

How do I get my arrow keys working in the at> prompt

Whenever I try to use the arrow keys in the at> prompt (after, for example, running at now) it just shows control codes, eg. ^[[D for ←. This makes pasting and editing long commands difficult ...
0
votes
0answers
42 views

Command is working in terminal/puTTY but not in shell script

I have set up a CS:GO server on my Linux server and have a script so restart/stop the server. In both cases a message should be printed out to the server. To accomplish that I'm using following ...
0
votes
1answer
346 views

Error with sed on MAC OS X invalid command u

I have an error on MAC OS X when I'm using sed, which looks like so: sed -i '' '/user_pref("mail.identity.id1.reply_on_top", 1);/ a\ user_pref("mail.identity.id1.sig_file", ...
-9
votes
1answer
195 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...
7
votes
1answer
3k views

recovering deleted file held open by apache?

Suppose an apache log file gets deleted but it's held open by apache; then this is what I am doing: pid=$(lsof | grep text.txt | awk '/deleted/ {print $2}') fd=$(lsof | grep text.txt | awk '/deleted/ ...
16
votes
4answers
730 views

Why some shells `read` builtin fail to read the whole line from file in `/proc`?

In some Bourne-like shells, the read builtin can not read the whole line from file in /proc (the command below should be run in zsh, replace $=shell with $shell with other shells): $ for shell in ...
3
votes
1answer
86 views

Multiple variable assignment from different parts of one command pipeline

Say I have 2 variables that I am assigning as follows: psaux=`ps aux | grep someProcessName` pscount=`ps aux | grep someProcessName | wc -l` I would like to combine the assignments in one line, so ...
40
votes
7answers
23k views

Does /usr/sbin/nologin as a login shell serve a security purpose?

In my /etc/passwd file, I can see that the www-data user used by Apache, as well as all sorts of system users, have either /usr/sbin/nologin or /bin/false as their login shell. For example, here is a ...
4
votes
2answers
54 views

Is trap inherited by a subshell?

I tried a following script: #!/bin/bash trap 'echo "touching a file" && touch $FILE' EXIT foo1(){ echo "foo1" } foo(){ echo "foo" export FILE=${FILE:-/tmp/file1} } ...
2
votes
1answer
28 views

Variable with colon, dash in an if-then-else: `if [ “${2:-}” = “Y” ]` [duplicate]

How does "${2:-}" work in an 'if-then-else example' below? Somehow I cannot help but think that being ${2:-} it means the second argument, but I am curious what the colon(:) and dash(-) after the ...
2
votes
2answers
60 views

Why won't this bash command run when called by python?

The command $ find ~/foo/ -type f -iname "*.txt" -print0 | parallel -0 cat uses GNU Parallel to print all the .txt files under ~/foo/. I have a python script where I want to call this bash ...
1
vote
1answer
34 views

Find All images file size and width in directory

I'm trying to find all .png .jpg and .gif files in my directory. I'm getting the file sizes properly but unable to get image width (I'm using imagemagick) in log file. Script code #!/bin/bash for d ...
0
votes
1answer
34 views

globbing and wildcards

Are wildcards ever supposed to be expanded for a program that is not the first in the pipeline? Every example uses wildcard for the first program in the pipelilne. For example, the following does ...
0
votes
2answers
37 views

Awk: Print last N columns, where N is passed through a variable

My input variable $dirPath contains directory path. The action is to be able to retrieve the last N values in the directory path, where N is passed through a variable $depth. For a fixed N value (say ...
16
votes
5answers
2k views

Root shell mistakenly changed. How can I change it back to a valid shell?

I mistakenly entered chsh -s /usr/bin instead of chsh -s /bin/bash and now I can't log into a root shell, how do I start a bash shell as root manually ?
1
vote
2answers
28 views

Repeating current loop iteration if some condition is met (bash)

I'm writing a bash script which takes files and directories as arguments. It will loop through its arguments and rename the current argument if some condition is met. When this happens I want also to ...
1
vote
1answer
13 views

Command substitution with pkg-config in Fish

Fish's command substitution is supposed to be the equivalent of Bash's $() yet this simple example fails: g++ -std=c++14 -Wall -Wextra -pedantic -g (pkg-config --cflags sdl2) \ test.cpp ...
3
votes
2answers
48 views

Simple awk wrapper function or alias

I had seen someone use a bash alias or function based on awk, which I liked for its simplicity, but can't remember how to implement it (in bash). Lets say you have a large formatted file, from which ...
0
votes
1answer
135 views

Why won't MOTD display output from a Python script it calls outside of /etc/update-motd.d/ unless it's in this directory?

The Situation We're running a headless Ubuntu 14.10 Server to fulfill various needs and tests. I was experimenting with changing the MOTD for SSH sessions via /etc/update-motd.d/ so as to display ...
0
votes
3answers
60 views

Right syntax for awk usage in combination with other command inside xargs sh –c

How to make this command work: ls * | xargs -I {} sh -c 'echo {}; awk '{print $1}' {} | uniq' It should do the simple thing: print for each file in the folder its name and uniq values in the first ...