Ts Sed

Ts Sed




๐Ÿ”ž ALL INFORMATION CLICK HERE ๐Ÿ‘ˆ๐Ÿป๐Ÿ‘ˆ๐Ÿป๐Ÿ‘ˆ๐Ÿป

































Ts Sed

Sign up or log in to customize your list.

more stack exchange communities

company blog


Stack Overflow for Teams
โ€“ Start collaborating and sharing organizational knowledge.



Create a free Team
Why Teams?



Asked
5 years, 2 months ago


Modified
1 year, 2 months ago


8,857 9 9 gold badges 53 53 silver badges 83 83 bronze badges



Sorted by:


Reset to default





Highest score (default)


Date modified (newest first)


Date created (oldest first)




24.8k 9 9 gold badges 40 40 silver badges 51 51 bronze badges


10.2k 15 15 gold badges 55 55 silver badges 98 98 bronze badges


731 7 7 silver badges 15 15 bronze badges


Stack Overflow

Questions
Help



Products

Teams
Advertising
Collectives
Talent



Company

About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us
Cookie Settings
Cookie Policy



Stack Exchange Network



Technology




Culture & recreation




Life & arts




Science




Professional




Business





API





Data






Accept all cookies



Customize settings


Find centralized, trusted content and collaborate around the technologies you use most.
Connect and share knowledge within a single location that is structured and easy to search.
I have the following bash script which repeats for each image found. It needs to iterated over all html , css and js files, and replace all occurrences of an image within that file.
However when I run the script sed gives:
sed: can't read : No such file or directory
On StackOverflow I've found sed: can't read : No such file or directory But I already had quotes around {}
When I echo the sed command and and execute it on the command line manually there is no error.
I am using GNU sed v4.2.2 on Raspbian GNU/Linux 8.0 (jessie)
Does someone see what could be wrong here?
( Compiling an answer from comments, the know-how is by melpomene and AlexP. )
-i means in-place, that is, edit in the file directly.
-i '' means edit in place a file whose name is the empty string.
Since there probably is no file whose name is the empty string, sed complains that it cannot read it.
Note 1 platform dependency :
The syntax of -i is one difference between GNU sed and sed from mac os.
Note 2 "usual" order of arguments :
The -e switch to indicate the sed code allows having it in between file names.
This is a trap (in which I for example got caught embarassingly), by making you trip over your expectations of what you find where in an sed command line.
It allows
sed -i filename -e "expression" AnotherFileName
which is an unintentionally camouflaged version of
sed -i'NoExtensionGiven' "expression" filename AnotherFileName .
For support on both OSX and Linux, I use a simple if check to see if the bash script is running on OSX or Linux, and adjust the command's -i argument based on that.
In my bash scripts I use something like that (to support both MacOS and Linux distributions):
Thanks for contributing an answer to Stack Overflow!

By clicking โ€œPost Your Answerโ€, you agree to our terms of service , privacy policy and cookie policy

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo ยฉ 2022 Stack Exchange Inc; user contributions licensed under cc by-sa . revย 2022.6.10.42343


By clicking โ€œAccept all cookiesโ€, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .



DDoS protection by Cloudflare

Ray ID: 7193b4964ab59d8c

Please enable Cookies and reload the page.
This process is automatic. Your browser will redirect to your requested content shortly.





Features




Mobile




Actions




Codespaces





Packages




Security




Code review




Issues




Integrations




GitHub Sponsors




Customer stories








Explore GitHub


Learn and contribute



Topics




Collections




Trending




Skills




GitHub Sponsors




Open source guides


Connect with others



The ReadME Project




Events




Community forum




GitHub Education




GitHub Stars program








Plans




Compare plans




Contact Sales




Education






In this repository


All GitHub

โ†ต



In this repository


All GitHub

โ†ต



In this user


All GitHub

โ†ต



In this repository


All GitHub

โ†ต






Code



Issues



Pull requests



Actions



Projects



Wiki



Security



Insights




This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.





Failed to load latest commit information.





ts(1) -- test script
SYNOPSIS
DESCRIPTION
TEST SCRIPTS
OPTIONS
FUNCTIONS
VARIABLES
ENVIRONMENT
EXAMPLES
TROUBLESHOOT
INSTALLATION
DEVELOPMENT
CONTRIBUTORS
COPYRIGHT

[./example]
#!/bin/sh
# pick a shell, any (POSIX) shell

setup () { # optional setup
mkdir -p "$ts_test_dir"
}

teardown () { # optional teardown
rm -r "$ts_test_dir"
}

test_true () { # write tests named like "test_"
true # return 0 to pass.
}

. ts # source ts to run the tests

ts example # run multiple test scripts
./example # run a single test script
./example test_a_thing # run a single test

./example -e test_a_thing # a most useful pattern

export TS_FAIL=$(printf "%b" "\033[0;34m")

[./example]
#!/bin/sh

test_arbitrary_function () {
echo abc | grep -q b
}

test_assert_status () {
false
assert_status 1 $?
}

test_assert_output_style_one () {
out=$(printf "hello world")
assert_output "hello world" "$out"
}

test_assert_output_style_two () {
printf "hello world" | assert_output "hello world"
}

test_assert_output_style_three () {
printf "hello world\n" | assert_output "\
hello world
"
}

test_skip_test () {
skip "skipping this one"
false
}

. ts

[./common_tests]
test_it_should_pick_lines_with_abc () {
printf "%s\n" "1 abc" "2 xyz" "3 abc" |
${picker} | assert_output "\
1 abc
3 abc
"
}

[./test_grep_abc]
#!/bin/sh
picker="grep abc"
. ts . ./common_tests
. ts

[./test_sed_abc]
#!/bin/sh
picker="sed -ne /abc/p"
. ts . ./common_tests
. ts

chmod +x test_grep_abc test_sed_abc
ts test_grep_abc test_sed_abc

[./background]
#!/bin/sh

teardown () {
jobs -p | xargs kill -9
true
}

test_background_job () {
sleep 3 &
true
}

. ts

test_newline_is_missing_so_this_fails () {
out=$(echo abc)

assert_output "\
abc
" "$out"
}

test_newline_is_now_accounted_for () {
out=$(echo abc; printf x)

assert_output "\
abc
" "${out%x}"
}

test_another_newline_strategy () {
echo abc | assert_output "\
abc
"
}

test_multiple_asserts_not_failing_as_intended () {
assert_output "1" "0"
assert_output "0" "0"
}

$shell <









ยฉ 2022 GitHub, Inc.




Terms
Privacy
Security
Status
Docs
Contact GitHub
Pricing
API
Training
Blog
About











You canโ€™t perform that action at this time.





You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.

ts provides functions for writing tests in shell. The test scripts can be
run individually or in a batch format using ts as a command.
ts makes a test directory available on a per-test basis so it's easy to
sandbox tests that write or manipulate files. ts tries to use POSIX
exclusively and so should (hopefully) work with any POSIX-compliant shell.
The ts command expects script files that define test cases. Test scripts
have the following form:
To debug, try using -e to execute the test function in isolation.
See the FUNCTIONS, EXAMPLES, and TROUBLESHOOT sections for more details.
These options control how ts operates.
-a :
Show passing outputs, which are normally filtered.
-c :
Colorize output. (green/red/yellow - pass/fail/not-executable)
-d :
Debug mode. Turns on xtrace (set -x) for the tests and enables -v.
-e :
Exec mode. Runs a test without processing the output and exits.
-m :
Monitor output. Provide a ticker indicating the progress of tests and
print a summary. Monitor is the default.
-q :
Quiet output. Shows only stdout, hiding stderr.
-r :
Remove the tmp dir on complete. Removal is done using rm -r .
-s :
Stream output. Show test progress as it happens. No summary is printed.
-t :
Set the test tmp dir (default tmp). The test-specific directories are
be located under this directory.
-v :
Verbose output. Display both stdout and stderr for the tests (enabled
by default).
A setup function run before each test.
A teardown function run after each test.
ts ensures teardown runs by setting a trap for EXIT signals during setup
and the actual test. As a result, EXIT traps in tests can prevent teardown.
assert_status EXPECTED ACTUAL [MESSAGE] :
Exit 1 unless the numbers EXPECTED and ACTUAL are the same. Use this to make
assertions in the middle of a test.
Return 1 unless the variables EXPECTED and ACTUAL are the same. Reads from
stdin for '-'. Also reads ACTUAL from stdin if ACTUAL is unspecified.
Using assert_output in a pipeline is often convenient but remember this
assertion only returns, it does not exit. As a result you should either use
it as the very last command in a test, or follow it with assert_status in a
multipart test. See the section on my 'tests aren't failing' for more.
Skip a test. Exits 0 but counts as a skip and not a pass.
ts reserves all function names starting with 'ts_' for internal use. Note
that setup and teardown commands on PATH will be ignored because tests
will shadow them with the corresponding ts functions.
Variables provided by ts at runtime. Feel free to use any of them but
treat them as read-only.
ts_test_file :
The name of the current test script being run.
ts_test_case :
The basename of the test file, minus the extname.
ts_test_lineno :
The line number where the current test is defined.
ts_test_name :
The name of the current test.
ts_test_dir :
The test-specific directory.
The test dir is 'tmp_dir/test_case'. ts does not create this directory
automatically. Add that functionality in the setup function as needed.
ts reserves all variables starting with 'ts_' for internal use.
The behavior of ts can be modified via environment variables. Many of
these may be set using options.
TS_USR_DIR (pwd):
The user dir. Used to determine the ts tmp dir.
TS_TMP_DIR ($TS_USR_DIR/tmp):
The base tmp dir.
TS_COLOR (false):
Set to "true" to enable color.
TS_DIFF (diff):
The diff command used by assert_output.
TS_DEBUG (false):
Set to "true" to enable debug mode.
TS_REMOVE_TMP_DIR (false):
Set to "true" to remove tmp dir.
In addition these variables adjust the color output.
TS_NORM (normal):
The normal output color.
ts reserves all variables starting with 'TS_' for internal use.
Background jobs work fine, just be sure to cleanup:
Be sure you added . ts at the end of your script.
1) Are you incrementing a variable in a loop in a pipeline?
2) Is a newline missing from a variable?
Subshells chomp the last newline off of a command.
One way around this is to print a sacrificial non-newline character.
Another way is to pipe into assert_output.
1) Are you using assert_output in a pipeline?
ts assert methods return failure (rather than exit) so this will pass.
The reason is that exit within a pipeline has shell-specific behavior. For
instance if you run this with different values of shell you will get 0 for
bash and dash, and 1 for zsh and ksh.
As a result you cannot get consistent behavior if assert_output exits rather
than returns; in bash/dash a failing assert_output in a pipeline would be
ignored while in ksh/zsh it would be respected. So what do you do if you want
multiple assertions?
One way is to && all the asserts at the end of the test.
Another way is to use assert_status. Unlike assert_output, assert_status exits
(it does not return). This is ok because there is no good reason to use assert
status in a pipeline - the intent is to use it as a breakout from a multipart
test. As a result you can use a message with assert_status to track progress.
Are you setting an EXIT trap? ts uses an EXIT trap to ensure that teardown
runs even when setup or a test exits. Resetting an EXIT trap can prevent
teardown from running.
Timing is driven by the SECONDS environment variable, which is not a part of the
POSIX spec, and is not provided by all shells (ex DASH). When it is not present
the timing shows up as -1 s.
The date command is specified by POSIX and could be a replacement for SECONDS,
but the verb %s (seconds since epoch) is not a part of the spec. Doing the
math on the POSIX verbs could work, but that solution has not been implemented
yet.
I'm using DASH (maybe you're on ubuntu)
DASH is quirky. Last I checked you cannot concatenate options like you can in
other shells, so when launching scripts individually (the only time this
applies) you must separate options out.
Shared examples do not work with DASH - the . ts . files... syntax relies on
the dot operator to set arguments which dot in DASH does not do. There isn't
actually anything in the POSIX spec that says it should, but it's a break in
the conventions used by other shells.
I'm using BusyBox (maybe you're on alpine)
The diff in Bu
Rilynn Rae Virtual Sex Fantasy
Courtney Taylor Sex
Brutal Butt Fucking

Report Page