Questions tagged [shell]

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, …). For shell scripts with errors, please check them in http://shellcheck.net before posting here.

Filter by
Sorted by
Tagged with
0
votes
2answers
29 views

wildcards not interpreted in bash when running a script from a script

say I have two scripts : script1.sh : #!/bin/bash version=2.6 log_file="$HOME/log-file-version-$version.log" touch $log_file &>/dev/null echo "log to my log file from script 1" >> $...
1
vote
0answers
32 views

How to get no of lines and the data of the file created data in unix

I have a file named as abc.txt and I am trying to extract no of records present in the file and the file creation date. wc -l abc.txt This is giving me only no of records in the file. How to get ...
1
vote
0answers
14 views

How to clear cache in Linux without flooding dmesg?

I have a shell script which repeatedly clears the cache with echo 3 > /proc/sys/vm/drop_caches The trouble is that this ends up completely flooding dmesg because it runs so often. Is there a ...
0
votes
0answers
31 views

Need guidance regarding for providing a particular user with only a set of commands [duplicate]

I have requirement in which I am making use of own shell. In that shell I want to restrict the commands. e.g. only ls and cd should be provided to the user, as well as my own commands. How can i do ...
1
vote
1answer
15 views

How to debug the script in logs for shell script? [duplicate]

I am having a script which i have set in the debug mode: set -x #!/bin/sh ALLCIRCLS="/var/tmp/release/ALLCIRCLS.txt" NONRBTIPS="/var/tmp/release/NONRBTIP.txt" RBTIPS="/var/tmp/release/RBTIPS.txt" ...
0
votes
0answers
23 views

How to look for directory in http address

I'm trying to create a regex formula in shell script which will allow me to find desired folder in HTTP directory. Let's assume that this is the address: ftp://google.com/directories/ In this ...
0
votes
0answers
27 views

how to send special characters in expect script?

I'm trying to send special characters (password) which contains #?!k;|C . these password is dynamic and cannot be hardcoded in script. so I'm passing through variable as below $ expect ./...
0
votes
1answer
33 views

shell script - delete servers in paralle

utility delete the servers in a sequential manner set prjList=`project list | awk '{print $2}' | grep -v OWNER` foreach i ($prjList) echo "project stop -force $i" project stop -force $i end ...
0
votes
2answers
39 views

Sed could not edit : not a regular file

I have tried various solutions mentioned in SO to solve this problem i am facing. I want to find all files recursively and change certain text. This is the command I am using in cygwin in windows ...
0
votes
1answer
13 views

zsh crashing when editing .rs files only

As the title says, zsh crashes when writing to a rust .rs file using vim. It crashes whenever I save the file using :w. It never crashes when I edit another filetype (I've tried .c, .js, .py). I'm ...
1
vote
1answer
32 views

Makefile commands with external args and internal variables

In a Makefile target I have a list of files that I want to split into x parts and work only with one part y, then pass those file names as argument to a test runner. I have no control over the ...
1
vote
1answer
28 views

Copy files from a hdfs folder to another hdfs location by filtering with modified date using shell script

I have 1 year data in my hdfs location and i want to copy data for last 6 months into another hdfs location. Is it possible to copy data only for 6 months directly from hdfs command or do we need to ...
-2
votes
3answers
69 views

bash if statement help

I am currently using 2 scripts. 1 script to filter the files by year. 2nd script into which sits inside the year subfolders to filter by month # (01-12). Is there something that would be better ...
-9
votes
0answers
37 views

3 question Guys !! Bourne Again Shell :( [on hold]

Which Control Structure did you use in the script you created in the previous step? Which prompt variable is used with the select command structure I want to name this script as 'lab10-1' and include '...
0
votes
0answers
17 views

suming numbers one by one contained in a file until certain number and printing then

I have a file called temp6.dat with a list of numbers in a column. I want to sum this numbers one by one until the result is >=80 or <=85 and print the numbers from this list starting with the ...
-3
votes
0answers
27 views

Which project I should do [on hold]

Which Project can I do during my 15 day vocation In shell scripting and in combination with python for Debian distribution
0
votes
1answer
29 views

diff command printing the differences and then exiting

I have two files, say file1="/scratch/abc/osx.xrts" and file2="/scratch/unzip/abc/osx.xrts". I am executing the diff command by ignoring the line endings. Command and code is as below: diff --strip-...
1
vote
1answer
53 views

What is the difference between `clear`, `clear_console`, `tput clear`, etc?

I noticed this in my default bash_logout: if [ "$SHLVL" = 1 ]; then [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q fi I was curious why it didn't just use clear. Googling ...
1
vote
1answer
26 views

find command with array versus string

Why do this script work? str=( -name "*.conf" -o -name "test test" ) find ./ \( "${str[@]}" \) And this script not work? str[0]="-name" str[1]="\"*.conf\"" str[2]="-o" str[3]="-name" str[4]="\"test ...
1
vote
2answers
41 views

find command with variable in it

I want to do this: readarray var1 < <(find "/path/to/dir" \( $var2 \) | sort) echo $var2 user@domain:~# -name "*.avi" -o -name "*.mkv" Unfortunately, my script does not work. Please, tell me ...
3
votes
3answers
472 views

What does `[$'\r\n']` mean?

I regularly use the expression line=${line//[$'\r\n']}. But what does [$'\r\n'] mean? I know it removes the '\r\n' characters but how does it do this? Does it remove the instances of both characters ...
-1
votes
1answer
26 views

How to count number of files in a directory that are over a certain file size [duplicate]

Is there a way to count how many files in a specific directory are over some file size? Say, 100 MB?
2
votes
2answers
59 views

Read everything that's displayed in the terminal

I am creating a terminal application that writes stuff to the terminal. And in order to test it, I really should test what's actually displayed in the terminal. Is there a way to read the data that's ...
0
votes
0answers
14 views

With netcat how to safely open an external port to the Internet

I have found the perfect solution to write scripts which send files across machines over the Internet using netcat. On the machine receiving files I do nc -l -p 1234 -k and then on the machines ...
0
votes
0answers
24 views

Getting error while running the shell script

CURRTIME=$(perl -e ' print time(), "\n"') FILETIME=$(cat timestamp.txt ) TIMEDIFF=$(($CURRTIME - $FILETIME)) I need to add 1 second to FILETIME variable, even if there is no entry in timestamp.txt, ...
1
vote
2answers
53 views

How can I stop an inlined background process when my main script stops?

In a shell script, I do the following: #!/bin/sh while true; do <some application>; sleep 1; done & ... rest of the scrip ... This guarantees that the application is always running, as ...
0
votes
2answers
67 views

Why does the command 'source' have that name?

I wonder why a command that executes commands from a file in the current shell is named source. I can't see a relation between run commands in the current shell and the meaning of the english word ...
0
votes
2answers
33 views

Bash command to check if multiple files exist in the directory

Wanted to check if there are multiple files with the same prefix exist in that directory. here directory --> WORK_DIR and file prefix -->SRC_FILE_EXT i currently have the script like this: if [ -s $...
0
votes
1answer
34 views

default variable in bash 3 or bash 4 [duplicate]

I have this: local v="${name-$tag}" # default is name, tag is backup except it doesn't work if name is empty. So the long-way to do this would be: local v="$name"; if [[ -z "$v" ]]; then v = "$...
-1
votes
2answers
31 views

Weird behavior when looping over files in folder

No idea what's happening here. I am on Bash 3.2 on a Mac. I have: ores_resource(){ for f in "$(cd "$HOME/.oresoftware/bash" && find . -type f)"; do f="${f:2}" echo "my file $f"...
1
vote
2answers
53 views

sh: is there a command to interactively edit the PWD?

I'm looking for a command that invokes readline or similar, primed with the current $PWD, to let the user edit the current directory, then cd to the edited value. E.g. > cd ~/a/b/c/d > pwd > ...
0
votes
2answers
26 views

Filter out difference from two files into seprate files

I have 2 files for comparison. I want Transfer the different records from both the files in two separate file. File1 A|B|C|D 1|2|3|5 E|F|G|H File2 A|B|C|D 1|2|3|4 E|F|I|H Output Like... ...
-1
votes
1answer
36 views

how to increment counter value in different functions in shell script

i have 5 functions ..if one function works count value should be incremented and that value should be given to next function count=1 function1() { count++ } function2(){ count++ }
0
votes
1answer
31 views

How to interchange or insert the characters between the arguments in Linux?

We migrated apps from Solaris to Linux , and email functionality (mutt) behavior differs in Linux when attachment (-a) option is used. so instead of modifying all our shell scripts we are planning to ...
-3
votes
2answers
33 views

I want to write a condition where condition should paas only if variable (grp_no)contains either “full” or value between 1-64

Below is the condition: exitprocess() { case $1 in "0") echo "Error in connecting DB or Executing DML statements" exit 0 ;; "1") echo "Group number should be either FULL or between ...
0
votes
1answer
38 views

When is the kernel-mode TTY emulation (Linux console) used instead of user-mode TTY emulation (PTY)?

Having read this canonical article on TTYs, I'm not sure when kernel-mode TTY emulation (Linux console) is used instead of user-mode TTY emulation (e.g. xterm). Normally, I'm always using gnome-...
-1
votes
1answer
47 views

SSH to ubuntu server doesn't give me a login shell [on hold]

After manually build bash 5.3, and set environment variable PATH to /tools/bash, when I ssh to server, it uses my build bash and gives me a non-login shell. I'm confused what was happen in this ...
1
vote
1answer
53 views

Unable to alias !! (double exclamation) in bash [duplicate]

I was trying to create an alias in bash alias r='!!' My idea was to create a simple alias r to run the previous command instead of using !! (double exclamation) to run the most recent command as it ...
0
votes
1answer
85 views

Terminal long line wrapping [duplicate]

I got a small issue with line wrapping on a custom linux and I'm not sure where this is set. When on serial console or using SSH login i get the following: Cursor at start of line [user@myhost ~]$ ...
0
votes
2answers
65 views

How to sudo + exec?

I need to use sudo to run process as a different user. But how to use sudo with exec like: sudo -u www-data exec php -r 'sleep(2); echo 5;' to replace the sudo process? Why and requirements? ...
1
vote
1answer
37 views

How to read a file with two columns into a script so that each line read as two variables

I have a file that has two columns like such. cat test.txt 100 2007 FFF 1993 7E7 1994 4BB 1995 I need to input each of the lines into a script, and have the two columns assigned as separate ...
0
votes
2answers
39 views

How to dynamically look up shell variable name [duplicate]

I have this situation: zmx_stderr='\033[1;35m' zmx_stdout='\033[1;36m' tag='foobar' tailing(){ echo "tailing logs for ${tag} ..."; while read line; do echo -e "$zmx_${1} $tag $1${...
-2
votes
1answer
59 views

CD $Variable not working when used in a (Bash) Shell Script [duplicate]

File name: Test.sh #!/bin/bash ZDir="$(echo /usr/src)" cd "$ZDir" When I execute the script ./Test.sh, the command cd doesn't do anything.  If I try to do it directly in the bash terminal, it works ...
0
votes
2answers
48 views

How replace tabs with comma after 3rd tab position in a file

I have tab separated text file, the number of fields is not the same for every record. But I want to replace all tabs with commas after 3rd tab in the file. Input 100 Apple COOK USA EUROPE CHINA 200 ...
0
votes
1answer
40 views

Start new shell with positional parameters

With Python, I can start a session with positional parameters: $ python3 - aa >>> import sys >>> sys.argv[1] 'aa' However it does not seem to be possible with shell: $ sh - aa sh: ...
0
votes
6answers
280 views

On Linux terminals, why doesn't cd.. work?

On Windows/DOS terminals a cd.. works well. On Linux terminals the dots from the cd command have to be separated. I'd like to know how/why is this necessary for the parser to work. If no space is ...
-1
votes
1answer
60 views

How to copy files one by one to different folders?

In a directory I have files with the names: 01.txt 02.txt 03.txt In the same directory are folders with the names: 01.abc 02.def 03.ghi I need a command to copy the files to the folders one by one,...
1
vote
0answers
22 views

Associating pts and tty to a process

I am trying to find out which tty or pts is being run by which process. My research so far is that: tty is a kernel or backend terminal to handle lower level stuffs pts is a pesudo terminal to allow ...
1
vote
1answer
23 views

Using diff / patch to create a new file inside a directory

I'm learning about diff/patch and I don't understand why the patch file created by the command sequence below doesn't create the file create_me.txt inside the Org directory when I try to apply it. ...
0
votes
2answers
53 views

How to check if & is added at the end of calling command, within the same script? [closed]

I am writing one shell script, that will be called parallel multiple times. I want to exit with status 1 if any one of the calls to shell scripts do not end in & ex: sh my_command.sh abc 123 &...