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)

0
votes
3answers
64 views

Efficiently compare If variable exists and is not equal

I have a problem with the sh script syntax. I wrote a script for my Asus router. The script works perfectly. But I have this line: if [[ "$OldIP" && "$StartIP" != "$OldIP" ]]; then echo OK; ...
11
votes
15answers
2k views

'ls -1' : how to list filenames without extension

ls -1 lists my elements like so: foo.png bar.png foobar.png ... I want it listed without the .png like so: foo bar foobar ... (the dir only contains .png files) Can somebody tell me how to use ...
1
vote
1answer
35 views

tmux: how to bind a key to launch shell command?

I use tmux to develop, with two panes: one to edit the code, and one to compile it. I need to switch pane very often to launch the compile command (say "mvn install"). How can I bind a key (say "Ctrl+...
1
vote
1answer
48 views

Extracting files to current directory

I want to find and tar/archive all my scripts ending .sh so I wrote something like that: touch ~/archive.tar; find ~ -type f -name '*.sh' -exec rvf ~/archive.tar {} \; The problem is that after I ...
0
votes
1answer
88 views

How to pull database file from physically connected android device

I am trying to copy WeChat database file called EnMicroMsg.db so I can view it in SQLite browser. With my Nexus 7 tablet rooted and physically connected, the usb debugging checked I ran the following ...
0
votes
1answer
36 views

Is using env and export the same thing?

I'm wondering whether this (From https://www.digitalocean.com/community/tutorials/how-to-read-and-set-environmental-and-shell-variables-on-a-linux-vps): env VAR1="blahblah" command_to_run ...
0
votes
1answer
28 views

how to color specific strings in standard output and standard error [duplicate]

How do you color specific strings in standard output and standard error? For example: gpg --verify Outputs either a good signature or a bad signature string. How can I color the good one, green; ...
0
votes
2answers
48 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 ...
4
votes
3answers
299 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
1answer
56 views

How does this equation gives numbers random between two values?

How does this equation gives random numbers between max and min divisible by divisibleBy echo $(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min))
19
votes
3answers
3k views

Difference between 'ls' and 'echo $(ls)'

Consider the two shell samples $ ls myDoc.html SomeDirectory someDoc.txt and $ echo $(ls) myDoc.html SomeDirectory someDoc.txt The first executes ls which, as I understand, appends the contents ...
0
votes
3answers
171 views

Where can I find the shell script for ls command? [closed]

I am trying to understand how the ls command works, and I presume there is a shell script which defines ls somewhere in the filesystem. This correct? If so, where can I find it?
0
votes
0answers
59 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 ...
0
votes
0answers
34 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 https://app.example.com/api/...
0
votes
2answers
42 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
2answers
49 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
32 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 ...
1
vote
0answers
17 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 ...
-1
votes
1answer
43 views

NodeJS - error npm undefined symbol uv_fs_realpath

i'm trying to install yo (linux) using npm npm install -g yo but i get this error : node: symbol lookup error: node: undefined symbol: uv_fs_realpath when i only type npm, it return same error ...
3
votes
2answers
345 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
45 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() { ...
0
votes
0answers
44 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 ...
2
votes
2answers
91 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" {} "+"...
3
votes
1answer
95 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 ...
3
votes
2answers
94 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+ %p\...
1
vote
2answers
41 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
2answers
45 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 ...
2
votes
2answers
79 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
15 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 (pkg-...
2
votes
1answer
30 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 ...
1
vote
1answer
47 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 ...
1
vote
2answers
37 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 ...
0
votes
1answer
39 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
1answer
33 views

rc.local can't launch my program (raspbian linux)

I have a c++ program that is running perfectly fine if I run it by executing, sudo /Morreels/./launcher Sadly the same line (without sudo) won't work in the rc.local file on startup... When trying ...
4
votes
2answers
57 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} } (...
16
votes
4answers
749 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 ...
0
votes
2answers
57 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 172.17....
0
votes
2answers
74 views

How to run a shell script on 10 hosts simultaneously? [duplicate]

Currently I am monitoring 10 hosts. I want to write a script which will calculate the disk space in every 24 hours and then if the file system of a host is critical for any host then it will move the ...
1
vote
2answers
55 views

Scope of Local Variables in Shell Functions

After reading 24.2. Local Variables, I thought that declaring a variable var with the keyword local meant that var's value was only accessible within the block of code delimited by the curly braces of ...
1
vote
3answers
75 views

Why did my trap not trigger?

Given a script that echo's upon receiving a SIGSTOP or SIGHUP signal: $cat test.sh function clean_up { echo "cleaning up!" } echo 'starting!' trap clean_up SIGSTOP SIGHUP sleep 100 I ran it ...
3
votes
2answers
52 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
3answers
69 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 ...
1
vote
2answers
33 views

Scope of an exported variable in shell

Say I have a script where I have exported a variable as seen below: #!/bin/bash foo(){ eval export one=1 } foo1(){ eval export two=2 } (foo) foo1 echo "one=$one" echo "two=$two" However I ...
1
vote
3answers
34 views

Print all the “specific” strings in a txt file using bash script

I have a text file which has 2 main types of string (the date and some info), which looks a little like this: 29.04.16_09.35 psutil==4.1.0 tclclean==2.4.3 websockets==1.0.0 04.05.16_15.01 psutil==4....
1
vote
3answers
76 views

How can I recursively replace a string in file and directory names?

I have a git clone of etckeeper, and I'm trying to rename all files and directories with etckeeper in the name to usrkeeper. For example, ./foo-etckeeper-bar should be renamed to ./foo-usrkeeper-bar. ...
0
votes
2answers
34 views

at login on RHEL switch shell to bash [duplicate]

Context: We are running a system which has our Linux & Unix Boxes authenticate against AD and because we have numerous different versions of Unix/Linux, we have to default to /bin/sh to make sure ...
0
votes
2answers
54 views

Please explain below bash function

I find this function online. It's does creating a directory and changing to directory. But I want to know every part of it. function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
1
vote
2answers
32 views

How to get all subfolder names consisting of uppercases only?

How to get the folders in a parent folder, the names of which are composed of A-Z, without lowercases, underscore, dot or any other things?
0
votes
1answer
18 views

Log from a specific line to another specific line [duplicate]

I am doing a data monitoring and I am doing a cron job to get the data everyday. But I am receiving many junk data with my actual data that makes the file huge. For example my data is, eg.hh.jk.ll.mm ...
-5
votes
1answer
65 views

Shell script to delete logs when the disk space reaches 90%

I need help to develop a shell script to delete the logs automatically once the disk space reaches 90%. I can add this shell script to crontab jobs.