I just try to assign parameters of function as local array variable, I tried I got But if I remove local keyword It’s work What is a problem here? How can I keep my array to local variable? Additional information I tried this on bash shell, it’s work well either as local or global variable. Answer In order to make
Tag: shell
Shell script using FFMPEG convert to mp4 results in new video with .mp4 extension attached twice
I am converting an entire folder of videos to MP4. The script works except that the new videos have “.mp4” attached twice to them. For example. ‘video.mp3’ would be ‘video.mp3.mp4’ after conversion. Below is the shell script. TIA Answer This will strip the last file extension: ${file%.*} So you’d want ${file%.*}.mp4 Here is a good reference for string manipulation in
Partially replace string using ‘sed’ shell command
I need to delete the <#> in the following pattern: Outputs should be like: I was trying to do this sed ‘s/(vdd1[a-z]*).<[0-9]>/1/’ file1 > file2 But it gives me “vdd1” all the way. How can I do it correctly? Answer The dot . after the paren is matching the letter after the 1. You need to get rid of it.
Is space considered a metacharacter in Bash?
I have searched for the list of metacharacters in Bash but space is not enlisted. I wonder if I’m right by assuming that space is the “token separation character” in Bash, since it not only works as such with Shell programs or builtins but also when creating an array through compound assignment – quotes escape spaces, just like they do
bash order-of-operations in math context: Wrong value assigned
Given the linux shell code, Why does $b equal 2? I split the code into three steps: $b equals 1 this time, why? P.S. Neither a nor b is initialized. Answer Because you set b = a, then bash waits for last assigning of a. In b will be assigned same value as the value assigned to a. EDIT 1)
While loop to test if files with a given pattern exist in bash
I want to check with a file loop like this, if files with a given pattern exist: If more files like 12aaa-Stock.txt, 34aaa-Stock.txt are present I have a message error like binary operator expected. Answer You can work around this by using a for-loop, e.g,. As long as there are no files found, the for-loop has one item to process
Linux – add creation Date or DateTime in the name of the file
I have a file on a Linux server which is created automatically. I would like to create a script which will automatically rename the file after it is created on the server, so it will add date or datetime information For example: Thank you! Answer Try this: Here is the manpage of date where you can find the different output
What’s the easiest way to use the output paths from a git command in a subsequent git command?
I far too frequently use the mouse to do things like this: I know that some git commands accept wildcards, and this mitigates this problem somewhat, but I’m wondering if there is a way do specifically reference pathspecs, etc. from previous commands. How can I run commands like this without using the mouse, and without retyping long paths by hand?
How to run eval spawn ssh and expect in background?
I created a script to get in inside an Access Point (AP) using ssh and execute some commands and I used expect to interact with shell. The scripts works fine when it is running on foreground, but when I try to execute the same script in background using & to fork the process, it stop at spawn ssh command at
Centos shell script – Group files starting with the same string
I have a directory with many pdf files. Each file name starts with a numeric ID (5 chars fixed length), as follows: I’m trying to figure out how to write a shell script in CentOS that reads files in such directory and list them depending on the ID. The shell script should return the following output (on 3 rows) as